Author Topic: Mtext Letter Bullets Query  (Read 4525 times)

0 Members and 1 Guest are viewing this topic.

Ambo

  • Mosquito
  • Posts: 20
Re: Mtext Letter Bullets Query
« Reply #15 on: November 02, 2015, 08:57:10 AM »

Quote
You're welcome Ambo  :-)

I could incorporate the Quick Unformat function, but unless you are working with heavily formatted MText I think it may be overkill for this task - if you find yourself receiving unexpected results which include fragments of MText formatting, I can post a version of the function which incorporates it.

Lee



Hi Lee Mac,

Sorry to bother you but I'm getting some weird values again whilst running the code on some of our drawings.  The value that I sometimes get is "{\\W0".  I'm not sure but I think it has something to do with the mtext width. Is there any chance you can incorporate this to the function please? I already spent a lot of time trying to understand your code so I can tweak it but it's just too complex for me.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Mtext Letter Bullets Query
« Reply #16 on: November 02, 2015, 01:17:34 PM »

Quote
You're welcome Ambo  :-)

I could incorporate the Quick Unformat function, but unless you are working with heavily formatted MText I think it may be overkill for this task - if you find yourself receiving unexpected results which include fragments of MText formatting, I can post a version of the function which incorporates it.

Lee

Hi Lee Mac,

Sorry to bother you but I'm getting some weird values again whilst running the code on some of our drawings.  The value that I sometimes get is "{\\W0".  I'm not sure but I think it has something to do with the mtext width. Is there any chance you can incorporate this to the function please? I already spent a lot of time trying to understand your code so I can tweak it but it's just too complex for me.

Hi Ambo,

No problem - please try the following:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / sel )
  2.     (if (setq sel (ssget "_X" '((0 . "MTEXT") (8 . "Room_Description"))))
  3.         (getlastbullet (ssname sel 0))
  4.     )
  5. )
  6.  
  7. (defun getlastbullet ( ent / enx itm pos str )
  8.     (setq enx (entget ent)
  9.           str (cdr (assoc 1 enx))
  10.     )
  11.     (while (setq itm (assoc 3 enx))
  12.         (setq str (strcat (cdr itm) str)
  13.               enx (cdr (member itm enx))
  14.         )
  15.     )
  16.     (while (setq pos (vl-string-search "\\P" str))
  17.         (setq str (substr str (+ 3 pos)))
  18.     )
  19.     (if (setq rgx (vlax-get-or-create-object "vbscript.regexp"))
  20.         (progn
  21.             (setq str (LM:quickunformat rgx str))
  22.             (vlax-release-object rgx)
  23.         )
  24.     )
  25.     (if (setq pos (vl-remove nil (mapcar '(lambda ( c ) (vl-string-position c str)) '(46 9 32))))
  26.         (substr str 1 (apply 'min pos))
  27.         str
  28.     )
  29. )
  30.  
  31. ;; Quick Unformat  -  Lee Mac
  32. ;; Returns a string with all MText formatting codes removed.
  33. ;; rgx - [vla] Regular Expressions (RegExp) Object
  34. ;; str - [str] String to process
  35.  
  36. (defun LM:quickunformat ( rgx str )
  37.     (if
  38.         (null
  39.             (vl-catch-all-error-p
  40.                 (setq str
  41.                     (vl-catch-all-apply
  42.                        '(lambda nil
  43.                             (vlax-put-property rgx 'global     actrue)
  44.                             (vlax-put-property rgx 'multiline  actrue)
  45.                             (vlax-put-property rgx 'ignorecase acfalse)
  46.                             (foreach pair
  47.                                '(
  48.                                     ("\032"     . "\\\\\\\\")
  49.                                     (" "        . "\\\\P|\\n|\\t")
  50.                                     ("$1"       . "\\\\(\\\\[ACcFfHKkLlOopQTW])|\\\\[ACcFfHKkLlOopQTW][^\\\\;]*;|\\\\[ACcFfKkHLlOopQTW]")
  51.                                     ("$1$2/$3"  . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")
  52.                                     ("$1$2"     . "\\\\(\\\\S)|[\\\\](})|}")
  53.                                     ("$1"       . "[\\\\]({)|{")
  54.                                     ("\\$1$2$3" . "(\\\\[ACcFfHKkLlOoPpQSTW])|({)|(})")
  55.                                     ("\\\\"     . "\032")
  56.                                 )
  57.                                 (vlax-put-property rgx 'pattern (cdr pair))
  58.                                 (setq str (vlax-invoke rgx 'replace str (car pair)))
  59.                             )
  60.                         )
  61.                     )
  62.                 )
  63.             )
  64.         )
  65.         str
  66.     )
  67. )
« Last Edit: November 02, 2015, 05:36:18 PM by Lee Mac »

Ambo

  • Mosquito
  • Posts: 20
Re: Mtext Letter Bullets Query
« Reply #17 on: November 02, 2015, 03:57:52 PM »
Hi Lee Mac,

That's superb!  Thank you ever so much!

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Mtext Letter Bullets Query
« Reply #18 on: November 02, 2015, 05:36:09 PM »
You're most welcome Ambo  :-)

(apologies for misspelling your name in my last post - now corrected)