strange request: Switch all colors from bylayer to the same color

strange request: Switch all colors from bylayer to the same color

Anonymous
Not applicable
1,199 Views
7 Replies
Message 1 of 8

strange request: Switch all colors from bylayer to the same color

Anonymous
Not applicable

Okay, here's fairly strange request (as most people would like to do the opposite).

 

I would like to grab a drawing and have every single line and polyline switch their color from bylayer to the same color the layer is.

 

For example, Layer-01 is yellow, then the line would be set to color yellow. 

 

Currently, I isolate each layer individually, select all the lines, and switch them manually.  

 

I'm kind of looking for a 1 click solution (bonus points if it switches all polylines with global width other than 0 to 0, and then put every layer on 0).

 

I imagine, I would need some type of Lisp routine, but I have never messed with anything lisp.

 

I'm trying to export the CAD file, but bylayer shows as black (instead of the color of the layer).

 

Thanks! 

 

 

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

john.vellek
Alumni
Alumni

Hi @Anonymous,

 

I see that you are visiting as a new member to the AutoCAD forum. Welcome to the Autodesk Community!

 

 Have you checked in the Autodesk App Store? It looks like there might be some tools to help with this issue.

 

 

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


John Vellek


Join the Autodesk Customer Council - Interact with developers, provide feedback on current and future software releases, and beta test the latest software!

Autodesk Knowledge Network | Autodesk Account | Product Feedback
0 Likes
Message 3 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

There must be something in the air....  This thread also started today is pretty much the same request, except for also wanting linetypes.  Follow the link in Post 2 there, and see what you think.  Its operation could easily be restricted to color only, if that's all you need.

Kent Cooper, AIA
0 Likes
Message 4 of 8

Anonymous
Not applicable

Wow, that actually worked pretty well... 

Thanks!

0 Likes
Message 5 of 8

doaiena
Collaborator
Collaborator
Accepted solution

I'm a little late to the party, but i have already spent time writing the code, might aswell post it.

 

(defun c:test ( / )

;select all lines and polylines in the entire drawing
(if (ssget "X" '((0 . "LWPOLYLINE,LINE")))

;loop all objects and set their color, to the color of the layer they are in
(vlax-for obj (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-color obj (vla-get-color (vla-item (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) (vla-get-layer obj))))
  ;if the object is a polyline set its width to 0
  (if (equal (vlax-get-property obj 'ObjectName) "AcDbPolyline")
    (vla-put-constantwidth obj 0)
  )
)
(princ "No Lines and/or Polylines found in the drawing.")
)
(princ)
)

 

Message 6 of 8

Anonymous
Not applicable

Thanks doaiena, your works perfect  too (plus it switches all the polylines gloval width's to zero... which is fantastic!!)

 

One last request, how could I add into the script so it erases the context of a particular layer... let's call it "Layer-X"

 

For example, I know I don't really need to export the content of "defpoint" and "area-calculation" layers

 

 

Thanks in advance for all your help!

 

EDIT- I just notice, it doesn't do anything on blocks. Could we also make the blocks to remain as blocks, but switch them to color of the layer?

I don't really need them to change their properties inside the block (if they are in layer 0 and "by layer" or a different color it won't matter after I export them).

 

Thanks

0 Likes
Message 7 of 8

doaiena
Collaborator
Collaborator

If i understand you correctly, you want to select lines and polylines from all layers, except from "defpoint" and "area-calculation". If that is the case just substitute this:

(ssget "X" '((0 . "LWPOLYLINE,LINE")))

 

with this:

(ssget "X" '((0 . "LWPOLYLINE,LINE")
            (-4 . "<NOT")(-4 . "<OR")
                                     (8 . "defpoint")
                                     (8 . "area-calculation")
            (-4 . "OR>")(-4 . "NOT>")
            )
)

PS:
If you want to add blocks to the selection, just change "LWPOLYLINE,LINE" to "LWPOLYLINE,LINE,INSERT".

Message 8 of 8

Anonymous
Not applicable

I actually want to "delete" the content of those two layers.

If I was doing it manually, I would un-freeze the layer, select all it's content, and then press delete and the purge the drawing.

 

I Will add "INSERT" and test it out... thanks!

 

0 Likes