TheSwamp
Code Red => VB(A) => Topic started by: ML on August 16, 2007, 12:51:34 PM
-
This one should be really easy but for some reason I am still getting an error
Does anyone see the problem???
Thank you
Mark
Sub AllLayersToByLayer()
Dim layer As AcadLayer
For Each layer In ThisDrawing.Layers
layer.color = acByLayer
Next layer
End Sub
-
.COLOR is obsolete. .TRUECOLOR is the new replacement.
What version of AutoCAD are you using? 2008 has a command called SETBYLAYER which you might want to look into.
Sub AllLayersToByLayer()
Dim color As AcadAcCmColor
Dim layer As AcadLayer
Set color = New AcadAcCmColor
With color
.ColorMethod = acColorMethodByACI
.ColorIndex = "256"
End With
For Each layer In ThisDrawing.Layers
layer.TrueColor = color
Next layer
End Sub
-
WOW
That's interesting Matt
You would think out of the 3 books I have and the help screens, they would have had a proper example
Let me give it a whirl
Thank you
Mark
-
Hi Matt
May be I wasn't totally clear; I am looking to change all layer colors to bylayer
Thank you
Mark
-
Did i have right understand? Change layer colors to ByLayer?
Of course you can do it but this could crash AutoCAD or dwg file (can't open it next time). I receive this error one time and have no wishes to repeat it.
Layer objects can't be with color ByLayer or ByBlock. You have to set color by ACI (from 1 to 255) or TrueColor.
-
Ahh
You make a good point
You would need to grab all the objects (entities) in the drawing and change the object names to ByLayer
I believe
Thank you
Mark
-
So you want all of the objects to be color bylayer, right? Example: A line is drawn on layer "TEMP" and layer "TEMP"'s color is blue, but the line shows as red, you want that line's color property to be changed to BYLAYER instead of 1 (red), correct?
If you're using 2008, SETBYLAYER is by far the best/fastest way to accomplish this.
If not, we'll have to come up with something (unless somebody has already rolled one that they'd like to pass around). ^-^
-
I am using 2006 and it doesn't exist in there :(
I tried this little bit of code:
Sub AllLayersToByLayer()
Dim Obj As Object
For Each Obj In ThisDrawing.ModelSpace
Obj.color = acByLayer
Next
End Sub
It says, get all objects in Modelspace and make them to Bylayer
-
But it is still not working
-
Non-programmatic way:
Select all objects, then in the properties dialog, select "Color", "ByLayer".
-
BOOOO!
You are no fun LOL :)
-
Try this.... (or use what DGCs suggests)
Sub AllLayersToByLayer()
Dim color As AcadAcCmColor
Dim obj As AcadEntity
Set color = New AcadAcCmColor
With color
.ColorMethod = acColorMethodByACI
.ColorIndex = "256"
End With
For Each obj In ThisDrawing.ModelSpace
obj.TrueColor = color
Next obj
End Sub
-
I know, sometimes I feel like a wet blanket.
:-)
-
No, I agree with you
I use to program just for fun, now I generally have a rule which is program out of nec.
However, somone earlier asked if you can globally change all objects to bylayer at once, so the intellect kicked in :-( LOL
I thought it would take me 5 minutes to put together but it obviously didn't LOL
There are somethings you can do.
I could use the filter command in acad and ask him specifically what layers he runs into this the most with, then create a filter that he could run.
It's no big deal really, I am just curious now
Mark
-
Matts code is what you need then.
-
I did a similar thing in lisp a few years ago, except it goes beyond what you can do with the Properties Palette. Such as unlocking any unlocked layers first, includes all objects in all layouts and in all blocks, then resets any locked layers.
-
I did a similar thing in lisp a few years ago, except it goes beyond what you can do with the Properties Palette. Such as unlocking any unlocked layers first, includes all objects in all layouts and in all blocks, then resets any locked layers.
Wasn't that "All2ByLayer"? I think I used/modified something like that of yours, but alas, now that 2008 has SETBYLAYER, well..... I just don't need it anymore. I hope you understand. It's not you; it's me. :lol:
-
This is worth a look (http://www.theswamp.org/index.php?topic=8573.0)
-
Here is what I use, modify to suit
Public Sub Everythingbylayer()
Dim objSelected As Object
Dim OBJSELSET As AcadSelectionSet
Dim N As Integer
On Error GoTo ERR_HAND
ThisDrawing.SetVariable "CECOLOR", "BYLAYER"
ThisDrawing.SetVariable "CELTYPE", "BYLAYER"
Set OBJSELSET = ThisDrawing.SelectionSets.Add("EBL")
OBJSELSET.Select acSelectionSetAll
For Each objSelected In OBJSELSET
objSelected.color = acByLayer
objSelected.Linetype = "ByLayer"
objSelected.Lineweight = acLnWtByLayer
objSelected.Update
Next
ThisDrawing.SelectionSets.Item("EBL").Delete
ZoomExtents
ThisDrawing.Application.Update
Exit_Here:
Exit Sub
ERR_HAND:
Select Case Err.Number
Case -2145320851
ThisDrawing.SelectionSets("EBL").Delete
Resume
Case -2145386413
Resume Next
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
End Sub
-
This is worth a look (http://www.theswamp.org/index.php?topic=8573.0)
Wow, I forgot all about that! Cool blast from the past, thanks DGCs
-
I just looked at SETBYLAYER, and I had everything but the material and plot style options. It also processes blocks, FYI, just in case you miss the prompt. Some of my blocks are hard coded to layers on purpose
-
I just looked at SETBYLAYER, and I had everything but the material and plot style options. It also processes blocks, FYI, just in case you miss the prompt. Some of my blocks are hard coded to layers on purpose
Nested blocks, too!
-
Yes
Matts code did work fine
I had forgotten to put some objects in my drawing to test it DUH LOL
I will certainly keep it for future use
And yes, of course you could do a Ctrl A to select all objects, then choose Bylayer from the pulldown
Dam intellect LOL
Thanks Matt
-
Here is MP's solution.. (http://www.theswamp.org/index.php?topic=3020.msg37746#msg37746)
-
Thanks Matt
You're welcome.
You got plenty of good solutions here, so use whatever works best for you.
-
Yes
Matt yours worked well, I was making the silly mistake of trying to change a lyer's property to bylayer.
Well, that won't work because Bylayer is the object's property and you got it.
Yes, your code worked fine
I saved the above code as well because I like how he applied the selection set to achieve the same result with a bit more functionality
Mark
-
To be complete you need to add an Mtext to bylayer function (As in make the text inside the mtext bylayer). I've found some client drawings have all their mtext forced to another color.
Yuk.