Change layer based on colours

Change layer based on colours

DHoskings4UN25
Explorer Explorer
1,652 Views
5 Replies
Message 2 of 6

Change layer based on colours

DHoskings4UN25
Explorer
Explorer

I am looking for a routine to either change the layer of objects with a certain colour to a different layer or use Map Explorer to query in a file an move objects with specific colours to layers in the current file.  If anyone has create a routine for this or knows how to get a CAD expression to do this, please let me know.


Example:  objects coloured 7 move to layer Object1; objects coloured 152 move to layer Object2, etc.

 

Thanks,

Dave

0 Likes
Accepted solutions (1)
1,653 Views
5 Replies
Replies (5)
Message 1 of 6

DHoskings4UN25
Explorer
Explorer

I am looking for a routine to either change the layer of objects with a certain colour to a different layer or use Map Explorer to query in a file an move objects with specific colours to layers in the current file.  If anyone has create a routine for this or knows how to get a CAD expression to do this, please let me know.


Example:  objects coloured 7 move to layer Object1; objects coloured 152 move to layer Object2, etc.

 

Thanks,

Dave

0 Likes
Message 3 of 6

Sea-Haven
Mentor
Mentor

Did you google found a few.

 

change object layer by color autocad lisp

0 Likes
Message 4 of 6

3wood
Advisor
Advisor

You can try CHZ20.

There is a 'By File' option. You can make the whole drawing as a block and then change object layers.

1000.jpg

Rotate 11.JPG

You need get a free registration to use this function.

 

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

Try this [very lightly tested], EDITing in your own list of color-Layer pairings:

 

(defun C:C2L ; = Color {to} Layer
  (/ C2Lpairs ss n)
  (setq C2Lpairs '((7 "Object1") (152 "Object2") (222 "Object3") (1 "RedStuff")))
  (foreach color (mapcar 'car C2Lpairs); list of color numbers only
    (if (setq ss (ssget "_X" (list (cons 62 color))))
      (repeat (setq n (sslength ss)); then
        (entmod
          (append
            (entget (ssname ss (setq n (1- n)))); entity data list
            (list (cons 8 (cadr (assoc color C2Lpairs)))); Layer name
          ); append
        ); entmod
      ); repeat
    ); if
  ); foreach
  (princ)
); defun

 

Doing the Layer change with (append)ing a Layer entry to entity data makes each Layer if it doesn't already exist [with default properties -- color 7, continuous linetype, etc.].  If you can be sure the Layers will already exist, it can be simplified a little, changing the Layer of all objects to the Layer at once with CHPROP, rather than stepping through and changing it for each object individually.

Kent Cooper, AIA
Message 6 of 6

DHoskings4UN25
Explorer
Explorer

Your script worked well and the creation of layers if they do not already exists allows for flexibility without concern that the correct template file is open, thanks

0 Likes