MLEADER LISP - CHANGE TEXT TO TITLE TEXT

MLEADER LISP - CHANGE TEXT TO TITLE TEXT

Anonymous
Not applicable
4,021 Views
13 Replies
Message 1 of 14

MLEADER LISP - CHANGE TEXT TO TITLE TEXT

Anonymous
Not applicable

I have several mleaders in my drawing. Each of them have text that is in all caps. I want to change the text to title text. I have tried several of the lisp routines found on other sites with no luck. I wouldn't say they completely didn't work. The issue is that I have multiple lines of text in my mleaders. When I use the lisp routines, the top line changes to title text but the rest of the lines are erased.

 

I am new at posting to forums, please bare with me.... 

I am attaching the lisp routine that I tried along with two screen shots....the first screen shot (TEXT-1) is before running the lisp. The second screenshot is the result of using the lisp. Why are the 2nd and 3rd lines disappearing? Can anyone fix the current lisp or send me a lisp that will work? Also, I have to pick each mleader individually instead of using a crossing or selecting all. Can this be altered somehow in the lisp as well?

 

I have posted this in the Civil 3D section and received the following response from ChrisRS...."Since MLEADERs are AutoCAD objects not Civil3D objects, you may have better luck posting in the "AutoCAD" Forum". I hope someone here can help. Thanks in advance !!!!

0 Likes
Accepted solutions (1)
4,022 Views
13 Replies
Replies (13)
Message 2 of 14

roland.r71
Collaborator
Collaborator

Smiley Surprised Nice problem you got there.

Did you notice the text isn't realy gone, but just not displayed?

Check the object properties window, under Text, you'll see that Contents still holds the complete text.

 

The problem is caused by the formating code for [enter] (\P) being changed to lower case too.

 

As a result, it's no longer reckognized as a valid formatting code.

However, instead of showing "Help Me Fix\pthis Issue With\pthe Case" it get cut off at the \

i.e.: the Lee Mac function for changing the case isn't ment for multileader (or mtext) containing multiple lines (or any other formatting), as is.

 

If the [enter] realy is all there is, you might solve it by doing a search & replace on the result (\p > \P)

NOTE: as you might have noticed: "Fix\pthis" is handled as a single word! so you might need to add some spaces or something to make sure they are processed as multiple words.

 

Which means, you need to rewrite the LM:TitleCase function (or find a replacement) to make it work (correctly) for multiline/formatted text.

0 Likes
Message 3 of 14

Anonymous
Not applicable

I did a search for "\p" and to be replaced with "\P", the search found 0 results.

0 Likes
Message 4 of 14

roland.r71
Collaborator
Collaborator

 

(if
    (and ss
      (eq acmtextcontent
        (vla-get-contenttype (setq obj (vlax-ename->vla-object (ssname ss 0))))
      )
    )
    (progn
       (setq titletext (LM:TitleCase (vla-get-textstring obj)))
       (setq titletext (vl-string-subst "\P" "\p" titletext))
       (vla-put-textstring obj titletext)
    )  
)

 

 

This will do the trick. (Note: this still doesn't solve the issue of non-capitalized words)

0 Likes
Message 5 of 14

Anonymous
Not applicable

Do I just add this to the end of my existing lisp?

0 Likes
Message 6 of 14

Anonymous
Not applicable

I am not good with lisp routines. Can you post the complete lisp that will work?

0 Likes
Message 7 of 14

roland.r71
Collaborator
Collaborator

The following will take care of that issue as well:

(defun c:demo ( / *error* ss obj )

  (defun *error* ( msg )
    (setvar 'NOMUTT 0)
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (setvar 'ERRNO 0)
  (setvar 'NOMUTT 1)
  (princ "\nSelect Multileader: ")
  (while
    (not
      (or
        (setq ss (ssget "_+.:S:E:L" '((0 . "MULTILEADER"))))
        (= 52 (getvar 'ERRNO))
      )
    )
  )
  (if
    (and ss
      (eq acmtextcontent
        (vla-get-contenttype (setq obj (vlax-ename->vla-object (ssname ss 0))))
      )
    )
    (progn
       (setq titletext (vl-string-subst "\P " "\P" (vla-get-textstring obj)))
       (setq titletext (vl-string-subst "\P" "\p " (LM:TitleCase titletext)))
       (vla-put-textstring obj titletext)
    )  
) (setvar 'NOMUTT 0) (princ) ) (defun LM:TitleCase ( s / n ) (vl-list->string (mapcar (function (lambda ( x ) (setq n (if (and (or (not n) (= 32 n)) (< 96 x 123)) (boole 2 x 32) x)) ) ) (vl-string->list (strcase s t)) ) ) )

(the lines in red are new/changed)

 

 

What it does:

First it will add a [space] behind each \P

Then it changes the case

Finally it changes \p[space] back to \P (without the extra space)

Et voila.

(note: this will only work correctly for \P. If you ever encounter other formatting, you'll have the same problem)

0 Likes
Message 8 of 14

Anonymous
Not applicable

I just tried the complete lisp you posted. See the attached screenshot. It is still only showing the top line, but in the properties box list all the words that are not showing. Also, it capitalize the last let in the word "HelP".

0 Likes
Message 9 of 14

roland.r71
Collaborator
Collaborator

Right... My bad

I tested without any P inside my text and only 1 \P (which worked well)

Just used the same text as you do, with same result.

 

Escaping the \ helps, a bit (so, \\P instead of \P)... but only for the first 2 lines, the 3rd is unchanged (& gets cut off from displaying) & now my row height is suddenly messed up too...

 

hmmm... back to the drawing board...

0 Likes
Message 10 of 14

Anonymous
Not applicable

Roland.....thanks for your assistance, it is greatly apprciated!!!

0 Likes
Message 11 of 14

roland.r71
Collaborator
Collaborator
Accepted solution

Try this:

(defun c:demo ( / *error* ss obj )

  (defun *error* ( msg )
    (setvar 'NOMUTT 0)
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ)
  )

  (setvar 'ERRNO 0)
  (setvar 'NOMUTT 1)
  (princ "\nSelect Multileader: ")
  (while
    (not
      (or
        (setq ss (ssget "_+.:S:E:L" '((0 . "MULTILEADER"))))
        (= 52 (getvar 'ERRNO))
      )
    )
  )
  (if
    (and ss
      (eq acmtextcontent
        (vla-get-contenttype (setq obj (vlax-ename->vla-object (ssname ss 0))))
      )
    )
    (progn
       (setq titletext (vla-get-textstring obj))
       (setq lines nil)
       (while (> (setq pos (vl-string-position (ascii "\\P") titletext)) 0)
         (setq lines (append lines (list (substr titletext 1 pos)))
               titletext (substr titletext (+ 3 pos))
         )
      )
      (if (> (strlen titletext) 0)
         (setq lines (append lines (list titletext))
               titletext "")
      )
      (if lines 
         (foreach line lines
            (setq titletext (strcat titletext (LM:TitleCase line) "\\P"))
         )
      )
       (vla-put-textstring obj titletext)
    )

) (setvar 'NOMUTT 0) (princ) ) (defun LM:TitleCase ( s / n ) (vl-list->string (mapcar (function (lambda ( x ) (setq n (if (and (or (not n) (= 32 n)) (< 96 x 123)) (boole 2 x 32) x)) ) ) (vl-string->list (strcase s t)) ) ) )
0 Likes
Message 12 of 14

Anonymous
Not applicable

WORKED PERFECTLY......THANKS AGAIN ROLAND !!!!!

0 Likes
Message 13 of 14

roland.r71
Collaborator
Collaborator

You're welcome Smiley Wink

0 Likes
Message 14 of 14

mdd
Community Visitor
Community Visitor

Does anyone know how to change this lisp to ignore non-alpha characters such as parenthesis?  A parenthesis prior to an alpha character (no space) returns a lower case alpha character.

0 Likes