LISP To Change MLeaders to By Layer

LISP To Change MLeaders to By Layer

MrJSmith
Advocate Advocate
2,661 Views
4 Replies
Message 1 of 5

LISP To Change MLeaders to By Layer

MrJSmith
Advocate
Advocate

I can't get MLeader's arrow heads and leader lines to change color via LISP, ones created via the default "MLD" command. I am using the following command below to change everything to by layer. Referencing http://entercad.ru/acadauto.en/idh_mleader_object.htm, it says "The color of the leader line and arrowhead is controlled by the Color property, or by the DIMCLRD system variable.", yet the vlax-put-property color doesn't seem to be catching the heads/leader lines properly. I also tried adding the properties "LeaderLineColor" and "TrueColor" but neither attempt worked. Any ideas would be appreciated, thanks!

 

(defun All2BL ()
    (vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
        (vlax-for obj block
            (if (wcmatch (vla-get-objectname obj) "AcDb*Dimension,AcDb*Leader")
				(progn
					(foreach prop '(Color DimensionLineColor ExtensionLineColor TextColor)
						(vl-catch-all-apply 'vlax-put-property (list obj prop acbylayer))
					)
				)
				(progn
					(vl-catch-all-apply 'vla-put-color (list obj acbylayer))
				)
            )
        )
    )
)
0 Likes
Accepted solutions (1)
2,662 Views
4 Replies
Replies (4)
Message 2 of 5

dbroad
Mentor
Mentor

You're trying to address too many object types with your function and are wrapping all of your actual changes in a vlax-catch-all-apply function, which will hide any and all errors.

Build a subfunction for mleaders and get that to work. Then restructure your code to branch on object type and to address each one as it should without the catch-all apply's.  The errors can then be debugged and testing on that object type will tell you more about what needs to change.

 

I believe all of the individual properties within the mleader should be byblock, not bylayer. Then there is a single control level for the drafter so that if they judge a color override is necessary, they can apply it.  Regarding color, the sub-objects may require an IAcadAcCmColor object. I never need to control sub-object colors since I use the mlstyle command to preset and use the properties palette to just change layer.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 3 of 5

MrJSmith
Advocate
Advocate

Looks like you are correct, it wants an IAcadAcCmColor object. I can't figure out how to modify the IAcadAcCmColor object.

 

Using  (vlax-get-property obj 'LeaderLineColor), returns #<VLA-OBJECT IAcadAcCmColor 000000003df349a0>

Using (vla-get-ColorIndex (vlax-get-property obj 'LeaderLineColor))), gives color index of 3, which is expected.

So I tried (vla-put-ColorIndex (vlax-get-property obj 'LeaderLineColor) 1)), which doesn't change anything.

 

I also tried using (vla-put-ColorMethod (vlax-get-property obj 'LeaderLineColor) 192) but that also failed to do anything.

0 Likes
Message 4 of 5

dbroad
Mentor
Mentor
Accepted solution

If you save the IAcadAcCmColor object, then you can change it and set the color of the subobject of the mleader.

Example:

 

(setq llc (vla-get-LeaderLineColor obj));;obtain the IAcadAcCmColor for the leaderline
(vla-put-ColorIndex llc 0);;set the color to byblock (use 256 for bylayer)
(vla-put-LeaderLineColor obj llc);;save it back to the leader subobject.

A color object can also be created by using vla-getinterfaceobject but that is needlessly complicated.  The properties and methods available for the IAcadAcCmColor object are:

; Property values:
; Blue (RO) = 0
; BookName (RO) = ""
; ColorIndex = 256
; ColorMethod = 192
; ColorName (RO) = ""
; EntityColor = -1073741824
; Green (RO) = 0
; Red (RO) = 0
; Methods supported:
; Delete ()
; SetColorBookColor (2)
; SetNames (2)
; SetRGB (3)

 

 

Architect, Registered NC, VA, SC, & GA.
Message 5 of 5

MrJSmith
Advocate
Advocate

Yes Sir, you are correct! I had that epiphany in the shower last night and tried it out this morning.

 

(setq colorObj (vlax-get-property obj 'LeaderLineColor))
(vla-put-ColorMethod colorObj 192)
(vlax-put-property obj 'LeaderLineColor colorObj)

Thanks for the help!

 

 

 

(defun All2BL (/ colorObj) ;Sets everything to by layer including leaders
	(vlax-for block (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
		(vlax-for obj block
			(cond 
				((wcmatch (vla-get-objectname obj) "AcDb*Dimension,AcDbLeader")
					(foreach prop '(Color DimensionLineColor ExtensionLineColor TextColor)
						(vl-catch-all-apply 'vlax-put-property (list obj prop acbylayer))
					)
				)
				((wcmatch (vla-get-objectname obj) "AcDbMLeader")
					(setq colorObj (vlax-get-property obj 'LeaderLineColor))
					(vla-put-ColorMethod colorObj 192)
					(vlax-put-property obj 'LeaderLineColor colorObj)
					(vl-catch-all-apply 'vla-put-color (list obj acbylayer))
				)
				(T
					(vl-catch-all-apply 'vla-put-color (list obj acbylayer))
				)
			)
		)
	)
	(print "Everything has been set to by layer!")
	(princ)
)
0 Likes