I'm looking for a lisp routine to change layer color based on layer name

I'm looking for a lisp routine to change layer color based on layer name

David125
Collaborator Collaborator
2,212 Views
7 Replies
Message 1 of 8

I'm looking for a lisp routine to change layer color based on layer name

David125
Collaborator
Collaborator

Does anyone have a lisp routine to change layer colors based on suffex of layer name? I have some files that need a quick turn around time in printing many files, I don't have original pc3 file so I have to use our print scheme. Quickest way so far is to change colors in layer properties but it would be nice to have it happen as a function.

0 Likes
Accepted solutions (1)
2,213 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@David125 wrote:

Does anyone have a lisp routine to change layer colors based on suffex of layer name? I have some files that need a quick turn around time in printing many files, I don't have original pc3 file so I have to use our print scheme. Quickest way so far is to change colors in layer properties but it would be nice to have it happen as a function.


Sounds easy enough, what are the conditions? 

 

What about Layerstates Manager? that would work

0 Likes
Message 3 of 8

David125
Collaborator
Collaborator

I'd like set a color for all "-N" and "-NEW" layers to be a color assigned by user. I might have slight variations based on client input. Same goes for all "-D" and "-DEMO" layers. These would always be suffex of layer names. So, at prompt if it would ask for color to use on all new layers then prompt for color of all DEMO layers, then it would change color of all applicable layers in drawing. The drawing would be a sheet with xrefs attached, so I'd like to be able to change color of attached layers. I understand referenced drawing is not changed. It also seems possible that I could at a later time go into the reference and change the layer colors with the same routine.

If the suffex could be assingned by the user that would be great, but can survive without it. Is that enought information?

 

Can you apply a wildcard with layer states manager? As in to search for "-*NEW" layers and make them blue?

 

Still that is something I would have to do one drawing at a time. A lisp routine would allow me to apply the routine to many drawings useing batchscript to run it on many drawings.

 

0 Likes
Message 4 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@David125 wrote:

I'd like set a color for all "-N" and "-NEW" layers to be a color assigned by user. ....  Same goes for all "-D" and "-DEMO" layers. ....

 


For that particular situation:

 

(defun C:LCS (/ colorN colorD); = Layer Color by Suffix
  (setq
    colorN (getstring "\nColor for -N and -NEW Layers: ")
    colorD (getstring "\nColor for -D and -DEMO Layers: ")
  ); setq
  (command "_.layer"
    "_color" colorN "*-N,*-NEW"
    "_color" colorD "*-D,*-DEMO"
    ""
  ); command
); defun

 

It can easily be made to ask for the suffix, etc.

Kent Cooper, AIA
Message 5 of 8

Anonymous
Not applicable

Hi, I am looking for something very similar. We have an xref with multiple layers that have different prefixes (job numbers) but always have "(Master-E) New" or     "(Master-E) EXR" in it. Is there a way to make a lisp very similar to this that just changes the color of those layers?

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... We have an xref with multiple layers that have different prefixes (job numbers) but always have "(Master-E) New" or     "(Master-E) EXR" in it. Is there a way to make a lisp very similar to this that just changes the color of those layers?


If you want the same color for both categories, use wildcard *'s at both ends of those substrings if there might be more Layer name after the target part, and comma-delimited multiple Layer names:

 

(defun C:LCME (/ col); = Layer Color by Master-E
  (setq col (getstring "\nColor for (Master-E) New and (Master-E) EXR Layers: "))
  (command "_.layer" "_color" col "*(Master-E) New*,*(Master-E) EXR*" "")
); defun

 

or a version without any variables:

 

(defun C:LCME (); = Layer Color by Master-E
  (command "_.layer"

    "_color" (getstring "\nColor for (Master-E) New and (Master-E) EXR Layers: ")

    "*(Master-E) New*,*(Master-E) EXR*"

    ""

  ); command

); defun

 

If you want different colors for the two categories, change the names, and include * at the ends:

 

(defun C:LCME (/ colN colE); = Layer Color by Master-E
  (setq
    colN (getstring "\nColor for (Master-E) New Layers: ")
    colE (getstring "\nColor for (Master-E) EXR Layers: ")
  ); setq
  (command "_.layer"
    "_color" colN "*(Master-E) New*"
    "_color" colE "*(Master-E) EXR*"
    ""
  ); command
); defun

 

or just:

 

(defun C:LCME (); = Layer Color by Master-E
  (command "_.layer"
    "_color" (getstring "\nColor for (Master-E) New Layers: ") "*(Master-E) New*"
    "_color" (getstring "\nColor for (Master-E) EXR Layers: ") "*(Master-E) EXR*"
    ""
  ); command
); defun

 

Either could be made to be not case-sensitive, if needed, and/or could be made to verify valid color input, and probably some more things.

Kent Cooper, AIA
0 Likes
Message 7 of 8

Anonymous
Not applicable

Thank you very much. Is there any way to instead of asking for the color to just put in a color. For example color 8 for EXR and 3 for New?

0 Likes
Message 8 of 8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Thank you very much. Is there any way to instead of asking for the color to just put in a color. For example color 8 for EXR and 3 for New?


Certainly.  Try out the Layer command in the command-line usage by typing -Layer [with the hyphen prefix], and experiment with the prompts and options, and you'll be able to figure out how to do any of this stuff.

 

(defun C:LCME (); = Layer Color by Master-E
  (command "_.layer"
    "_color" "8" "*(Master-E) New*"
    "_color" "3" "*(Master-E) EXR*"
    ""
  ); command
); defun

 

One thing that might not be obvious is that I believe [I'm not on a computer with AutoCAD to confirm] that even with a numerical color, you need to include double-quotes around it, since the possibility of color words such as "red" requires that it be given a string, not a "raw" number.

Kent Cooper, AIA
0 Likes