select all layers of a particular color and send to back

select all layers of a particular color and send to back

mpa-la
Advocate Advocate
1,480 Views
6 Replies
Message 1 of 7

select all layers of a particular color and send to back

mpa-la
Advocate
Advocate

Hello all, I'm looking for a way to select all objects on layers of a given color so that I can then send all those objects to the back.  So say I have 35 layers that are color 8 in my drawing, I would issue the command, enter the number 8, then it would select all the objects that are on those 35 layers, and send them to the back.  I'm looking for a one command solution for efficient drafting, not a workaround, I got the workarounds already.  Thanks!!

0 Likes
Accepted solutions (1)
1,481 Views
6 Replies
Replies (6)
Message 2 of 7

chriscowgill7373
Advisor
Advisor

what do you have started for your code?

I would suppose you would prompt for the user to input a color, then look through the layer collection to find all of them that are that color, then create a selection set of the objects on that layer, and send that selection set to back.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 3 of 7

mpa-la
Advocate
Advocate

I'm not a programmer, just a user, I only know the bare essentials of lisp.  I do have a similar lisp routine that turns all layers off of a color you choose, perhaps that could be a jumping off point, but I don't know enough to tell.  Here it is if it helps.

 

;;;;;;;;;;;turns layers off by color

(defun c:loff nil

(or *LayOffByColor-color*
(setq *LayOffByColor-color* 1))

(setq *LayOffByColor-color* (acad_colordlg *LayOffByColor-color*))

(vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (= *LayOffByColor-color* (vla-get-color layer))
(vla-put-layeron layer :vlax-false)))
(princ)
)

;;;;;;;;;;;;

0 Likes
Message 4 of 7

chriscowgill7373
Advisor
Advisor
Accepted solution

you could try this:

(defun c:ldr (/ lcolor llist lset)
  (vl-load-com)
  (setq	lcolor (getint "\nPlease specify Layer color:")
	llist  ""
  )
  (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
    (if	(= (vla-get-color x) lcolor)
      (setq llist (strcat llist (vla-get-name x) ","))
    )
  )
  (if (setq llist (vl-string-right-trim "," llist))
    (progn (if (setq lset (ssget "x" (list (cons 8 llist))))
	     (command "draworder" lset "" "b")
	     (prompt "\no items on these layers")
	   )
    )
  )
  (princ)
)

Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 5 of 7

mpa-la
Advocate
Advocate

Thanks Christopher, that works perfect!!!!  What an awesome community, so appreciated!

0 Likes
Message 6 of 7

chriscowgill7373
Advisor
Advisor

No problem.  There isn't much error checking, I just threw it together and only tested in a few scenarios.  Its a start anyway.


Christopher T. Cowgill, P.E.

AutoCAD Certified Professional
Civil 3D Certified Professional
Civil 3D 2024 on Windows 10

Please select the Accept as Solution button if my post solves your issue or answers your question.

0 Likes
Message 7 of 7

Sea-Haven
Mentor
Mentor

For me I would change (setq lcolor (getint "\nPlease specify Layer color:") to pick an object and get color either bylayer or bycolor.

0 Likes