Select by color and then change to layer

Select by color and then change to layer

renanemeyer
Advocate Advocate
982 Views
9 Replies
Message 1 of 10

Select by color and then change to layer

renanemeyer
Advocate
Advocate

Hello everyone on the forum. I've been reading several posts like this one:

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/object-selection-with-color/td-p/850...

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/select-all-layers-of-a-particular-co...

 

 

In case I'm having trouble creating something similar. I would like a command that would select everything I have in color 7 and set it on the layer "LAY-W".
Does anyone know how to proceed with the modification for this?

 

 

 

0 Likes
Accepted solutions (1)
983 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Do you mean only things with color 7 assigned as a property override, or including things whose color is ByLayer but which are on Layers whose color is 7?

And do you mean all such things in the drawing, or only from among a User selection?

Kent Cooper, AIA
Message 3 of 10

renanemeyer
Advocate
Advocate

@Kent1CooperThanks for the answer!!

Yes, only things with color 7 assigned as a property override and it would be all such things in the drawing, not needing to do the selection of what would change.
In this case, would you know how it could be modified?

0 Likes
Message 4 of 10

paullimapa
Mentor
Mentor

would you share the code you have so far?


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

Kent1Cooper
Consultant
Consultant

@renanemeyer wrote:

.... only things with color 7 assigned as a property override and it would be all such things in the drawing....


Follow-up question:  Would they ever be in multiple different spaces?  If they're always only in Model space, it's rather simple to make something find all of them and collectively change their Layer with a CHPROP command.  But that won't do it if some are in different Paper space layouts, etc., in which case it can be done, but takes a different approach.

Kent Cooper, AIA
Message 6 of 10

renanemeyer
Advocate
Advocate

@Kent1Cooper in this case it would only be for only in the Model space. An idea you commented I think it would work then.
In this case, I create a ss1 variable filtering these elements by color and apply "command "chprop" ss1 "" "LAY-W" ?
I'm visualizing this mentally, but I can't make a code that works in this case

0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant
Accepted solution

@renanemeyer wrote:

.... I create a ss1 variable filtering these elements by color and apply "command "chprop" ss1 "" "LAY-W" ? ....


Yes.  But you need to call for the "_layer" option [i.e. which Property you want to change] before giving it the Layer name.  [Do it manually, and note the exact sequence of prompts and required inputs.]  And remember that the CHPROP will need an extra "" {Enter} at the end to tell it you're done [you could go on to change other Properties within the same command, so you need to let it know].

Try writing it, and if you can't make it work, show us what you came up with.

Kent Cooper, AIA
Message 8 of 10

renanemeyer
Advocate
Advocate

@Kent1Cooper Thank you for the tips! Its was accurate @paullimapa thank you for your availability, I only managed to write now
I managed to do the lisp again now and it worked!! Below is the script:

(defun c:LAYW ( / c d e l )
   (if (setq e (car (entsel)))
       (progn
           (setq c
               (cond
                   (   (cdr (assoc 62 (entget e)))   )
                   (   (abs (cdr (assoc 62 (tblsearch "LAYER" (cdr (assoc 8 (entget 

e)))))))   )
               )
           )                     
           (while (setq d (tblnext "LAYER" (null d)))
               (if (= c (abs (cdr (assoc 62 d))))
                   (setq l (cons "," (cons (cdr (assoc 2 d)) l)))
               )
           )
           (sssetfirst nil
               (ssget "_X"
                   (if l
                       (list
                           (cons -4 "<OR")
                               (cons 62 c)
                               (cons -4 "<AND")
                                   (cons 62 256)
                                   (cons 8 (apply 'strcat (cdr l)))
                               (cons -4 "AND>")
                           (cons -4 "OR>")
                       )
                       (list (cons 62 c))
                   )
               )
           )
       )
   )
	(command "_.chprop" (ssget ) "" "LA" "LAY-W" "")
   (princ)
)

 

0 Likes
Message 9 of 10

Kent1Cooper
Consultant
Consultant

That looks like it contradicts Message 3, in that it gets both things with the color as a property override and those of ByLayer color on Layers with that color.  Am I misunderstanding?

 

[And by the way, that's not a Script.  That word has a specific, and although related, different meaning in AutoCAD.]

Kent Cooper, AIA
0 Likes
Message 10 of 10

renanemeyer
Advocate
Advocate

That's right @Kent1Cooper, its getting both. I read this idea on the forum and get it for this case.

By the way, sorry for misreferencing the script.

0 Likes