change the colour properties for all layouts and details

change the colour properties for all layouts and details

karfung
Advocate Advocate
1,708 Views
29 Replies
Message 1 of 30

change the colour properties for all layouts and details

karfung
Advocate
Advocate

Hi Sir,
Kindly advise, step or lisp, how to change the colour properties for all layouts and details in a single AutoCAD file. 

0 Likes
Accepted solutions (4)
1,709 Views
29 Replies
Replies (29)
Message 2 of 30

imadHabash
Consultant
Consultant

Hi and Welcome to AutoCAD Forum,

If you're talking here about Layers...

  • In a single CAD file You have to make it manually and one by one.
  • For multi-CAD files you can try LAYTRANS (Command).

Imad Habash

EESignature

0 Likes
Message 3 of 30

vinodkl
Mentor
Mentor

Hello @karfung 

 

You can change the color properties for all layouts and details in a single AutoCAD file by applying a plot style (.ctb) to every layout so the chosen colors are controlled uniformly during plotting.

--------------------------------------------------------------------------------------------------------------------------
ವಿನೋದ್ ಕೆ ಎಲ್( System Design Engineer)
Likes is much appreciated if the information I have shared is helpful to you and/or others.

Please mark "Accept as Solution" if my reply resolves the issue or answers your question, to help others in the community.
--------------------------------------------------------------------------------------------------------------------------
0 Likes
Message 4 of 30

paullimapa
Mentor
Mentor

You can use this simple code to cycle through each layout and assign vp color to 7 for all layers in all vports:

(foreach itm (layoutlist) (setvar "ctab" itm)(command "_.Pspace" "_.Vplayer" "_Co" "7" "*" "_All" ""))

But if you have any objects assigned with their own colors then you'll have to run the following lisp function cbyl to change all objects Color assignment to Bylayer:

(defun c:cbyl (/ ctab setbylayermode)
 (setq ctab (getvar "ctab")) ; save current tab 
 (setvar "ctab" "Model") ; change to Model tab
 (setq setbylayermode (getvar "setbylayermode")) ; save current settings
 (setvar "setbylayermode" 1) ; change color to bylayer only
 (command "_.Layer" "_Unl" "*" "") ; unlock all layers
 (command "_.Setbylayer" "_All" "" "_Y" "_Y") 
 (setvar "setbylayermode" setbylayermode) ; restore original settings
 (setvar "ctab" ctab) ; restore original layout
 (princ) ; clean exit
) ; defun

If there are xrefs, you'll have to set Xrefoverride to


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 30

karfung
Advocate
Advocate

Hi imadhabash, 

Only certain layer needs to be changed. Therefore, your method is not suitable. 

Using Lisp with be good. thanks. 

0 Likes
Message 6 of 30

karfung
Advocate
Advocate

Hi paullimapa, 

Thanks for your reply. Could we enhance the Lisp by adding the step after the Lisp is entered in the command bar as below, 

1). Ask which layer to change the colour properties. (This allows the user to select the area using the cursor.) 
2). What colour code to be used? (User to enter the colour code)

3). Finish and appear in model space.

 

Condition:

1). The activity to be done in model space only. 

2). A certain layer is involved. 

3). Shall allow user for the colour code. 

 

Thanks. 

 

0 Likes
Message 7 of 30

paullimapa
Mentor
Mentor
Accepted solution

Questions;

1). Ask which layer to change the colour properties. (This allows the user to select the area using the cursor.) ”

Do you want the user to select objects on the drawing area and then those layers objects are on would have the color change or should a list box be presented to select from a list of layer names?


The activity to be done in model space only. ”

If this is what you really want you can do this now using the Layer manager window 

Changing a layers color in model space automatically changes all layers color in all  vports unless there are vport color overrides. Or you want VP colors changed which is what my initial response covers? Please clarify. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 30

karfung
Advocate
Advocate

Hi paullimapa,
If this is what you really want you can do this now using the Layer manager window. 

Some of the layer colour in the block or attribute may unable to change. If this happened, any advise to resolve. 

 

Thanks. 

0 Likes
Message 9 of 30

paullimapa
Mentor
Mentor

Try the cbyl lisp function I posted in my initial reply and see if that solves the problem 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 30

karfung
Advocate
Advocate

Hi paullimapa,
Colud the CBYL include, 

1). To ask change to what colour code. By this, eventually, all the layers changed to the colour code the user wanted. 

2). Change the colour as requested for the arrow in the dimension also. 

 

Kindly advise. 

Thanks. 

 

0 Likes
Message 11 of 30

paullimapa
Mentor
Mentor

To clarify the CBYL lisp function basically runs AutoCADs built in setbylayer command so that all objects color assignments are now based on the Layer they are on.  Now you can use the Layer Properties Manager window to select and change the layers to the desired Color. 
Im not awared that the Dimension arrows colors still won’t change to Bylayer. Maybe these are controlled inside the Dimension Style. Could you include a sample dwg with these Dimensions so I can take a look?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 30

paullimapa
Mentor
Mentor
Accepted solution

Found this lisp function that changes all dimensions including arrows & leaders to color bylayer:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-to-change-mleaders-to-by-layer/...

(defun c: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)
)

After copy & pasted the code and saving as all2bl.lsp you do the following to load it at the command prompt:

(load "all2bl")

Then to run it at the command prompt enter:

All2Bl

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 13 of 30

karfung
Advocate
Advocate

 

karfung_0-1766070205534.png

 

Yes, this is working. Could you do me a favour to revise as follows,

1). The function is not working on mtext.

2). The function is not working on the item to be an array. 
Thanks. 

0 Likes
Message 14 of 30

paullimapa
Mentor
Mentor

please clarify where this is in the dwg:

"item to be an array"


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 15 of 30

karfung
Advocate
Advocate

the red colour dot as per picture or drawing. 

0 Likes
Message 16 of 30

paullimapa
Mentor
Mentor

Ok, found a couple of lisp functions on-line that will take care of both of your wish list:

MText = StpMtext.lsp (modified to remove Color formatting only)

by TWilley
 
Array Blocks = BENL0.lsp (changes all selected Block Entities to layer 0)

 

After loading & running both those lisp functions this is how your dwg looks like now:

paullimapa_0-1766129267022.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 17 of 30

karfung
Advocate
Advocate

It not working. Could provide the complete lisp with change the drawing1 to 1 colour? 

It have change for leader, mtext & arrary for red dot. 

Thanks

0 Likes
Message 18 of 30

paullimapa
Mentor
Mentor
Please clarify what you mean by this:
"...change the drawing1 to 1 colour?
 

I've combined into a single file All.lsp which includes the following functions (some modified for this project) and automatically executes them all after loading:

Cbyl, All2Bl, StpMtext, BENL0CL
(load"all")
 

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 19 of 30

karfung
Advocate
Advocate

this is not working. kindly review the LISP again. 

Thanks. 

0 Likes
Message 20 of 30

karfung
Advocate
Advocate

karfung_0-1766166552699.png

It is not working for DIM and array of the red dot. 

Thanks. 

0 Likes