change color to all layers

change color to all layers

f_rivaXGG6C
Contributor Contributor
985 Views
4 Replies
Message 1 of 5

change color to all layers

f_rivaXGG6C
Contributor
Contributor

i would need to change the color of all layers that have several colors into one (specifically color 252) using a lisp command (i need to integrate it into a larger command), do you know how to do this?
thank you very much for your help

0 Likes
Accepted solutions (1)
986 Views
4 Replies
Replies (4)
Message 2 of 5

pendean
Community Legend
Community Legend
Accepted solution
What did you try so far? the commandline sequence is quite straight forward
-LAYER
COLOR
252
*
<enter>

... how would you like to address those objects that have color overrides and ignore layer colors?
0 Likes
Message 3 of 5

LDShaw
Collaborator
Collaborator

Something like?

 

 

;;; ==============================================================================
;;; Lisp Name: foo
;;; Author: Lonnie
;;; Date Created: 2024-08-06
;;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/change-color-to-all-layers/td-p/12942402
;;; Last Edited: [Insert Last Edit Date]
;;;
;;; DESCRIPTION:
;;; A routine to change the color of all layers in the current AutoCAD drawing 
;;; to a specified color.
;;;
;;; Usage:
;;; 1. Load the Lisp routine.
;;; 2. Run the command "FOO" in AutoCAD.
;;;
;;; Parameters:
;;; color - The color number to apply to all layers.
;;;
;;; Returns:
;;; None
;;;
;;; Notes:
;;; - This routine changes the color of all layers in the current drawing to the
;;;   specified color.
;;;
;;; ---------------------------- Main program --------------------------------;

(defun c:foo (/ color layer)
  (vl-load-com)
  (setq color (getint "\nEnter the color number to apply to all layers: "))
  (vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (vla-put-color layer color)
  )
  (princ (strcat "\nAll layers have been changed to color " (itoa color) "."))
  (princ)
)

This won't change everything to by layer and hardly addresses blocks but

 

 





0 Likes
Message 4 of 5

f_rivaXGG6C
Contributor
Contributor

I had tried "_ai_selall" and "_all", it did not even remotely occur to me to use "*" to select which layers to change

those that have the override, i used the setbyalayer command

0 Likes
Message 5 of 5

f_rivaXGG6C
Contributor
Contributor
this solution is also interesting, which I will try to understand how it works and probably use in the future.
but for what I am doing now, the solution offered above is more straightforward.
thank you very much for the alternative solution
0 Likes