Multileader Text Color

Multileader Text Color

Anonymous
Not applicable
3,387 Views
14 Replies
Message 1 of 15

Multileader Text Color

Anonymous
Not applicable

Can anyone get me a lisp to change the color of the first line only of multileader text ?

0 Likes
Accepted solutions (1)
3,388 Views
14 Replies
Replies (14)
Message 2 of 15

pbejse
Mentor
Mentor

@Anonymous wrote:

Can anyone get me a lisp to change the color of the first line only of multileader text ?


That would be easy IF the new line is an actual return code. "The quick brown\\Pfox jumps over the lazy dog" Post a sample drawing Sherif.Magdy.

 

 

 

 

0 Likes
Message 3 of 15

DannyNL
Advisor
Advisor

Try this.

 

Can probably be coded a bit more easy and more optimized but it gets the job done.

And only basic MTexts and coloring supported at the moment.

 

(defun c:Test (/ T_Selection T_NewColor T_Entity T_NewText T_OldText T_Object T_LineBreak T_CurrentColor)
   (if
      (and
         (setq T_Selection (ssget '((0 . "MTEXT"))))
         (setq T_NewColor (acad_colordlg 1 nil))
      )
      (progn
         (setq T_NewColor (strcat "\\C" (itoa T_NewColor)))
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Entity (vl-remove-if '(lambda (T_Item) (listp (cadr T_Item))) (ssnamex T_Selection))
            (setq T_NewText nil)
            (setq T_OldText (vla-get-TextString (setq T_Object (vlax-ename->vla-object (cadr T_Entity)))))
            (cond
               (
                  (or
                     (and
                        (setq T_LineBreak (vl-string-search "\\P" T_OldText))
                        (setq T_CurrentColor (RegEX "\\\\C\\d+" (substr T_OldText 1 T_LineBreak)))
                     )
                     (setq T_CurrentColor (RegEX "\\\\C\\d+" T_OldText))
                  )
                  (progn
                     (setq T_NewText (vl-string-subst T_NewColor T_CurrentColor T_OldText))
                  )
               )
               (
                  (setq T_LineBreak (vl-string-search "\\P" T_OldText))
                  (progn
                     (setq T_NewText (vl-string-subst (strcat "{" T_NewColor ";" (substr T_OldText 1 T_LineBreak) "}") (substr T_OldText 1 T_LineBreak) T_OldText))
                  )
               )
               (
                  T
                  (setq T_NewText (strcat "{" T_NewColor ";" T_OldText "}"))
               )
            )                 
            (vla-put-TextString T_Object T_NewText)                  
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
   )
   (princ)
)         
               
(defun RegEx (RE_Pattern RE_SearchString / RE_RegExObject RE_Result RE_Return)
   (if
      (and
         (= (type RE_SearchString) 'STR)
         (= (type RE_Pattern)      'STR)
      )
      (progn
         (setq RE_RegExObject (vlax-get-or-create-object "VBScript.RegExp"))
         (vlax-put-property RE_RegExObject 'Pattern RE_Pattern)
         (setq RE_Result (vl-catch-all-apply 'vlax-invoke-method (list RE_RegExObject 'Execute RE_SearchString)))
         (if
            (and
               (not (vl-catch-all-error-p RE_Result))
               (> (vla-get-Count RE_Result) 0)
            )      
            (setq RE_Return (vla-get-Value (vlax-get-property RE_Result 'Item 0)))      
         )
         (vlax-release-object RE_RegExObject)
      )
   )
   RE_Return
)
0 Likes
Message 4 of 15

Anonymous
Not applicable

Thanks for your concern but this just changes MTEXT not Multileader Text

0 Likes
Message 5 of 15

DannyNL
Advisor
Advisor
Accepted solution

Oops....my bad!

Thought MText instead of Multileader. Luckily only one thing needs to be changed and that is MTEXT to MUTLILEADER in the SSGET Smiley Happy

 

(defun c:Test (/ T_Selection T_NewColor T_Entity T_NewText T_OldText T_Object T_LineBreak T_CurrentColor)
   (if
      (and
         (setq T_Selection (ssget '((0 . "MULTILEADER"))))
         (setq T_NewColor (acad_colordlg 1 nil))
      )
      (progn
         (setq T_NewColor (strcat "\\C" (itoa T_NewColor)))
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Entity (vl-remove-if '(lambda (T_Item) (listp (cadr T_Item))) (ssnamex T_Selection))
            (setq T_NewText nil)
            (setq T_OldText (vla-get-TextString (setq T_Object (vlax-ename->vla-object (cadr T_Entity)))))
            (cond
               (
                  (or
                     (and
                        (setq T_LineBreak (vl-string-search "\\P" T_OldText))
                        (setq T_CurrentColor (RegEX "\\\\C\\d+" (substr T_OldText 1 T_LineBreak)))
                     )
                     (setq T_CurrentColor (RegEX "\\\\C\\d+" T_OldText))
                  )
                  (progn
                     (setq T_NewText (vl-string-subst T_NewColor T_CurrentColor T_OldText))
                  )
               )
               (
                  (setq T_LineBreak (vl-string-search "\\P" T_OldText))
                  (progn
                     (setq T_NewText (vl-string-subst (strcat "{" T_NewColor ";" (substr T_OldText 1 T_LineBreak) "}") (substr T_OldText 1 T_LineBreak) T_OldText))
                  )
               )
               (
                  T
                  (setq T_NewText (strcat "{" T_NewColor ";" T_OldText "}"))
               )
            )                 
            (vla-put-TextString T_Object T_NewText)                  
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
   )
   (princ)
)         
               
(defun RegEx (RE_Pattern RE_SearchString / RE_RegExObject RE_Result RE_Return)
   (if
      (and
         (= (type RE_SearchString) 'STR)
         (= (type RE_Pattern)      'STR)
      )
      (progn
         (setq RE_RegExObject (vlax-get-or-create-object "VBScript.RegExp"))
         (vlax-put-property RE_RegExObject 'Pattern RE_Pattern)
         (setq RE_Result (vl-catch-all-apply 'vlax-invoke-method (list RE_RegExObject 'Execute RE_SearchString)))
         (if
            (and
               (not (vl-catch-all-error-p RE_Result))
               (> (vla-get-Count RE_Result) 0)
            )      
            (setq RE_Return (vla-get-Value (vlax-get-property RE_Result 'Item 0)))      
         )
         (vlax-release-object RE_RegExObject)
      )
   )
   RE_Return
) 
Message 6 of 15

dtiemeyer
Advisor
Advisor

@DannyNL

I'm wondering why 'ByLayer' cannot be chosen when this command is run. We receive drawings where we want to strip out color overrides from multileaders. Could you provide a tweak to this code to do what we need? Cheers!

My other CAD is a Cadillac and I like to Revit to the Max!
0 Likes
Message 7 of 15

ВeekeeCZ
Consultant
Consultant

@dtiemeyer wrote:

@DannyNL

I'm wondering why 'ByLayer' cannot be chosen when this command is run. We receive drawings where we want to strip out color overrides from multileaders. Could you provide a tweak to this code to do what we need? Cheers!


 

Well, allowing that is quite easy:

(setq T_NewColor (acad_colordlg 1 T))

...I didn't dive into all the code, but it seems to be working well.

Message 8 of 15

dtiemeyer
Advisor
Advisor

Thanks @ВeekeeCZ, that's a step in the right direction, but if there are multiple lines of mtext embedded in the multileader, it only sets the top line to 'ByLayer'. Is there a way to do all the text of a multileader? (and even the leader portion itself?)   Basically we just want to blast the entire thing to 'ByLayer'...

My other CAD is a Cadillac and I like to Revit to the Max!
0 Likes
Message 9 of 15

ВeekeeCZ
Consultant
Consultant

@dtiemeyer wrote:

Thanks @ВeekeeCZ, that's a step in the right direction, but if there are multiple lines of mtext embedded in the multileader, it only sets the top line to 'ByLayer'. Is there a way to do all the text of a multileader? (and even the leader portion itself?)   Basically we just want to blast the entire thing to 'ByLayer'...


 

Ouu, I thought that the routine works for you. But whatever - don't think this is the right tool for you.

Use THIS routine to strip MTEXT from a color. Then autocad's SETBYLAYER for MLEADER entity.

0 Likes
Message 10 of 15

dtiemeyer
Advisor
Advisor

wow, we actually use an older version of StripMtext, and it's great.  Unfortunately this new v5.0c says multileaders are supported, but it is not removing the color from the text embedded within them. I've also posted a question to the author of that app, perhaps he will respond. I've also attached an example file representing the problem - the multileaders are on Layer 0 (which is set to color 7), but both the leader and embedded mtext have green overrides - running StripMtext on them removes neither the green override of the leader nor the green override of the text.  😞 

My other CAD is a Cadillac and I like to Revit to the Max!
0 Likes
Message 11 of 15

ВeekeeCZ
Consultant
Consultant

Hmm, that's not an issue of the STRIPMTEXT. That should be solvable by SETBYLAYER. Not sure why it isn't. 

Anyway, this will fix that.

 

(defun c:MleaderColorByLayer ( / ss i)

  (if (setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
    (repeat (setq i (sslength ss))
      (setpropertyvalue (ssname ss (setq i (1- i))) "TextColor" 0)
      (setpropertyvalue (ssname ss i) "LeaderLineColor" 0)))
  (princ)
)
Message 12 of 15

dtiemeyer
Advisor
Advisor

That is awesome. Thank you!

My other CAD is a Cadillac and I like to Revit to the Max!
0 Likes
Message 13 of 15

ant7lop
Explorer
Explorer

can you change the code to select multileader and change the left attachment to left or right?  thank you

0 Likes
Message 14 of 15

ant7lop
Explorer
Explorer

sorry! quick question can you kindly make this lisp to change the change the left attachment to left or right with a selecting the multileader?  thank you

0 Likes
Message 15 of 15

ant7lop
Explorer
Explorer

Thank you for this lisp, I made some changes and it works for what I need I just want to say thank you very much

here are the small changes. now I can select the Multileader and it change the location of the leader either on top or bottom.  🙂

(defun c:ard ( / ss i)

(if (setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
(repeat (setq i (sslength ss))
(setpropertyvalue (ssname ss (setq i (1- i))) "TextRightAttachmentType" 3)
(setpropertyvalue (ssname ss i) "TextRightAttachmentType" 3)))
(princ)
)

0 Likes