Change MLeaderStyle Text Color

Change MLeaderStyle Text Color

ari.monteiro
Advocate Advocate
537 Views
1 Reply
Message 1 of 2

Change MLeaderStyle Text Color

ari.monteiro
Advocate
Advocate

Hi,

 

I wrote this code below for change mleaderstyle text color to 137 color number. But it didn't works on DWG attached.

 

 

 

(defun c:cml ()
  (setq dict   (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
      style    (dictsearch (cdr (assoc -1 dict)) "LEADER")
      newColor (cons 93 137)
  )
  (entmod (subst newColor (assoc 93 style) style))
)

Any have suggestions?

 

 

 

 

0 Likes
Accepted solutions (1)
538 Views
1 Reply
Reply (1)
Message 2 of 2

hmsilva
Mentor
Mentor
Accepted solution

@ari.monteiro wrote:

Hi,

 

I wrote this code below for change mleaderstyle text color to 137 color number. But it didn't works on DWG attached.

(defun c:cml ()
  (setq dict   (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
      style    (dictsearch (cdr (assoc -1 dict)) "LEADER")
      newColor (cons 93 137)
  )
  (entmod (subst newColor (assoc 93 style) style))
)

Any have suggestions?


Hi ari.monteiro,

colors in mleaderstyles are stored as negative colors, not index colors.

You'll have to transform index colors to negative color, before 'subst' the existing color, one way is using phanaem's RGB->VP-COL function.

 

(defun c:cml ()
  (setq dict   (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
      style    (dictsearch (cdr (assoc -1 dict)) "LEADER")
      newColor (cons 93 (RGB->VP-COL 137))
  )
  (entmod (subst newColor (assoc 93 style) style))
)

;http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/420-truecolor/m-p/4563361#M316324
;by phanaem
(defun RGB->vp-col (l)
  (apply '+
    (mapcar 'lsh
      (if (numberp l) (list 195 0 0 l) (cons 194 l))
      '(24 16 8 0)
    )
  )
)

Or you can use

 

 

(vl-load-com)
(defun c:demo (/ mleader_dict mlstyle textcolor)
   (setq adoc         (vla-get-activedocument (vlax-get-acad-object))
         mleader_dict (vla-item (vla-get-dictionaries adoc) "ACAD_MLEADERSTYLE")
   )
   (if (not (vl-catch-all-error-p
               (vl-catch-all-apply '(lambda () (setq mlstyle (vla-item mleader_dict "LEADER"))))
            )
       )
      (progn
         (setq textcolor (vla-get-textcolor mlstyle))
         (vla-put-colorindex textcolor 137)
         (vla-put-textcolor mlstyle textcolor)
      )
   )
   (princ)
)

 

Hope this helps,
Henrique

EESignature