Change all layers to Orange or Combine all layers to one layer

Change all layers to Orange or Combine all layers to one layer

sjelen
Contributor Contributor
1,154 Views
24 Replies
Message 1 of 25

Change all layers to Orange or Combine all layers to one layer

sjelen
Contributor
Contributor

Good morning all -

Looking for a little help here. I've gotten about 90% of the way there. I am having a hang up with changing all layers to one color, if this is not attainable then possibly I can combine all layers into one layer and change that one layer to the color I want. I was using the Layer Translator previously to combine all layers and then would choose the color I wanted that layer to be but again if I could just type in my command to perform all my functions that would be ideal. 

 

Thank you all for your help, here is my code so far. 

 

(defun c:TCD-PLB ()
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq layers (vla-get-Layers doc))
(setq newLayerName "XREF")

; Create a new layer
(setq newLayer (vla-Add layers newLayerName))
(vla-put-Color newLayer acOrange)
(vla-put-PlotStyleName newLayer "Normal")

; Delete dimensions on the "A-ANNO-DIMS" layer
(vlax-for obj (vla-get-ModelSpace doc)
(if (= (vla-get-Layer obj) "A-ANNO-DIMS")
(vla-erase obj)
)
)

; Delete dimensions on the "S-GRID-IDEN" layer
(vlax-for obj (vla-get-ModelSpace doc)
(if (= (vla-get-Layer obj) "S-GRID-IDEN")
(vla-erase obj)
)
)

; Delete gridlines on the "S-GRID-1" layer
(vlax-for obj (vla-get-ModelSpace doc)
(if (= (vla-get-Layer obj) "S-GRID-1")
(vla-erase obj)
)
)

; Delete gridlines on the "S-GRID-2" layer
(vlax-for obj (vla-get-ModelSpace doc)
(if (= (vla-get-Layer obj) "S-GRID-2")
(vla-erase obj)
)
)

(princ "\nTCD PLB executed successfully.")
)

(princ)

0 Likes
1,155 Views
24 Replies
Replies (24)
Message 2 of 25

pendean
Community Legend
Community Legend
Where'd you get that LISP? I'm curious because what you are asking for and what it does are not exactly a match.

Are you not just wanting to automate this commandline method, here to change all layers to color 1 for example
-LAYER <enter>
COLOR <enter>
1 <enter>
* <enter>
<enter>

OR as a button macro
-LAYER;color;1;*;;
0 Likes
Message 3 of 25

sjelen
Contributor
Contributor

Hi Pendean - I am looking to type in my command of TCD-PLB and have it perform all of the functions listed in the code. I have a significant amount of drawings that I need to make all those changes to and so if I could type in my command and have all those changes take place, that would be ideal. Does that make sense? All the code works so far with deleting the unnecessary information I need but I am having the issue with having the entire drawing be one color. 

 

Thanks for your response

0 Likes
Message 4 of 25

Kent1Cooper
Consultant
Consultant

@sjelen wrote:

..... I am having a hang up with changing all layers to one color, ....


(command "_.layer" "_color" 30 "*" "")

or other color number if 30 isn't the orange you want.

 

That won't take care of objects with other-than-ByLayer color property overrides.  Do you need that, too?  There are multiple topics in this Forum about changing the color and/or the Layer of everything, including objects nested in Blocks, that you can Search for.

Kent Cooper, AIA
0 Likes
Message 5 of 25

sjelen
Contributor
Contributor

Hi Kent1Cooper -

 

Yes I would need any fail safe that would grab layers that would not change color with that code you gave and have them switch to the orange color as well. Would we want to create a code line that changes all layers to bylayer then make the color change?

 

Thank you

0 Likes
Message 6 of 25

sjelen
Contributor
Contributor

Also, just through that code in and it was perfect! Awesome!!! 

 

Thank you for that!

0 Likes
Message 7 of 25

Kent1Cooper
Consultant
Consultant

@sjelen wrote:

.... Yes I would need any fail safe that would grab layers objects that would not change color with that code you gave and have them switch to the orange color as well. Would we want to create a code line that changes all layers objects to bylayer then make the color change?


(command

  "_.chprop" "_all" "" "_color" "ByLayer" ""

  "_.layer" "_color" 30 "*" ""

)

 

Or the reverse [Layer color change first, then object color].

But then there's the question of nested objects -- the above will only handle top-level ones.

Kent Cooper, AIA
0 Likes
Message 8 of 25

sjelen
Contributor
Contributor

OK scratch that, it is perfect that it changes the colors like I want but when I add that in with my code it changes the colors but does not delete any of the other information I want. If I place it at the end of my code I get an error but at the beginning of the code it changes the colors but nothing else. 

0 Likes
Message 9 of 25

Kent1Cooper
Consultant
Consultant

It sounds like you may not have put it in the right place.  You didn't say what the error is, either.  Show us your adjusted code.

Kent Cooper, AIA
0 Likes
Message 10 of 25

sjelen
Contributor
Contributor

OK shuffled some more things around and it worked that time but here it is again. 

(defun c:TCD-PLB ()
; Change color of all layers to orange
(command

"_.chprop" "_all" "" "_color" "ByLayer" ""

"_.layer" "_color" 30 "*" ""

)

; Delete dimensions on specific layers
(vlax-for obj (vla-get-ModelSpace doc)
(if (member (vla-get-Layer obj) '("A-ANNO-DIMS" "A-ANNO-DIMS-1" "S-GRID-IDEN"))
(vla-erase obj)
)
)

; Delete gridlines on specific layers
(vlax-for obj (vla-get-ModelSpace doc)
(if (member (vla-get-Layer obj) '("S-GRID-1" "S-GRID-2"))
(vla-erase obj)
)
)

(princ "\nTCD PLB executed successfully.")
)

(princ)

0 Likes
Message 11 of 25

sjelen
Contributor
Contributor

Sorry, I should really triple check myself before responding back. Closed the file out and opened it again to confirm it worked and that time it did not run completely, only changed everything to orange. 

0 Likes
Message 12 of 25

Kent1Cooper
Consultant
Consultant

Well, I don't very often work with those (vla-... functions, which for some reason are not documented in the AutoLisp Reference.  But here's a possibility:  The (member) functions looking at a list of Layer names would be case-sensitive.  Do you have any Layer names that don't match the case of those in the list?  Does it work if you do this?

 

(if (member (strcase (vla-get-Layer obj)) '("....

Kent Cooper, AIA
0 Likes
Message 13 of 25

sjelen
Contributor
Contributor

I'm not opposed to starting from scratch if you think we can achieve everything that current code attempts to do but eliminates the vlax coding.  

0 Likes
Message 14 of 25

Kent1Cooper
Consultant
Consultant

@sjelen wrote:

I'm not opposed to starting from scratch if you think we can achieve everything that current code attempts to do but eliminates the vlax coding.  


[It's not (vlax-.... coding that I rarely work with -- those functions are documented, as are (vl-.... and (vlr-.... functions.  It's just the (vla-.... functions that I wish were, so I could see the arguments expected and so on.]  Meanwhile, what about my question in Message 12?

Kent Cooper, AIA
0 Likes
Message 15 of 25

sjelen
Contributor
Contributor

I'm sorry that response in message 12 I didn't get to work. To your question I do not see any names that are different than what I'm calling out. 

I did try changing the code to be all command functions and can get the color to change but cannot get the "delete" function to work. Here is my code for that. 

 

(defun c:TCD-PLB ()
; Change color of all layers to orange
(command "_LAYER" "_Color" "30" "*" "")

; Delete dimensions on specific layers
(command "_._erase" (ssget "_X" '((8 . "A-ANNO-DIMS")(8 . "A-ANNO-DIMS-1")(8 . "S-GRID-IDEN"))))

; Delete gridlines on specific layers
(command "_._erase" (ssget "_X" '((8 . "S-GRID-1")(8 . "S-GRID-2"))))

(princ "\nTCD PLB executed successfully.")
)

(princ)

0 Likes
Message 16 of 25

Kent1Cooper
Consultant
Consultant

I don't know about those double underscores surrounding periods.  And you can string multiple Layer names together with comma separators in one code-8 entry -- it could be that the separate entries are a problem because nothing matches all of them.  Also, the selection needs to be completed with "" Enter.  Try these:

 

(command "_.erase" (ssget "_X" '((8 . "A-ANNO-DIMS,A-ANNO-DIMS-1,S-GRID-IDEN"))) "")

(command "_.erase" (ssget "_X" '((8 . "S-GRID-1,S-GRID-2"))) "")

Kent Cooper, AIA
0 Likes
Message 17 of 25

sjelen
Contributor
Contributor

ok HELL YES! I can confidently say this works! Now I added an extra line and I was hoping you could help me with something else. So every document will contain the ID-.... it's the drawing page and as it goes up the building that page number will change so is there a way to call out a layer name that contains like "contains" "ID-" where depending on what document I open it'll delete them?

 

Also this is for my duct file as the plumbing file didn't have the drawing in it. 

 

(defun c:TCD-DCT ()
; Change color of all layers to orange
(command "_LAYER" "_Color" "6" "*" "")

; Delete dimensions on specific layers
(command "_.erase" (ssget "_X" '((8 . "A-ANNO-DIMS,A-ANNO-DIMS-1,S-GRID-IDEN"))) "")

; Delete gridlines on specific layers
(command "_.erase" (ssget "_X" '((8 . "S-GRID-1,S-GRID-2,S-GRID-3"))) "")

; Delete drawing backgrounds
(command "_.erase" (ssget "_X" '((8 . "ID-109 - LEVEL D18 - LEVEL D25_dwg,ID-109 - LEVEL D18 - LEVEL D25_dwg-1"))) "")

(princ "\nTCD DCT executed successfully.")
)

Thank you!!!!

THA

 

(princ)

0 Likes
Message 18 of 25

sjelen
Contributor
Contributor

Also I thought if I included "ByLayer" in the "Layer" command function to change all layers to "ByLayer" but it did not work then I created it's own separate command to change all layers to "ByLayer" but that also didn't work. I have a different document that not all layers are changing color and it's because they are not on "By Layer".

 

Any thoughts?

 

Thanks

0 Likes
Message 19 of 25

Kent1Cooper
Consultant
Consultant

@sjelen wrote:

Also I thought if I included "ByLayer" in the "Layer" command function to change all layers to "ByLayer" but it did not work then I created it's own separate command to change all layers to "ByLayer" but that also didn't work. I have a different document that not all layers are changing color and it's because they are not on "By Layer". ....


"ByLayer" is an option for various properties of objects, not of Layers.  It has no place in a Layer command.  It would be appropriate in [for example] a CHPROP command to assign it as a color to selected objects.

Kent Cooper, AIA
0 Likes
Message 20 of 25

Kent1Cooper
Consultant
Consultant

@sjelen wrote:

.... So every document will contain the ID-.... it's the drawing page and as it goes up the building that page number will change so is there a way to call out a layer name that contains like "contains" "ID-" where depending on what document I open it'll delete them?

....


I'm not sure I understand, exactly.  Do you mean there will be a Layer with a Layer name that contains the sub-string "ID-"?  Or an object [Text, Mtext, maybe Attribute?] whose text content contains that sub-string?  What's the "them" at the end?  Get rid of the Layer(s)?  Can there be more than one such Layer in the same drawing?  Or just delete the Text [or whatever it is]?  By "document" do you mean "drawing file" or perhaps "Layout" within a larger drawing?

Kent Cooper, AIA
0 Likes