Author Topic: All Layers to ByLayer  (Read 7834 times)

0 Members and 1 Guest are viewing this topic.

ML

  • Guest
All Layers to ByLayer
« 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

Code: [Select]
Sub AllLayersToByLayer()

Dim layer As AcadLayer


For Each layer In ThisDrawing.Layers
 layer.color = acByLayer
 
Next layer

End Sub

Guest

  • Guest
Re: All Layers to ByLayer
« Reply #1 on: August 16, 2007, 12:58:21 PM »
.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.


Code: [Select]
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

ML

  • Guest
Re: All Layers to ByLayer
« Reply #2 on: August 16, 2007, 01:04:43 PM »

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

ML

  • Guest
Re: All Layers to ByLayer
« Reply #3 on: August 16, 2007, 01:10:04 PM »
Hi Matt

May be I wasn't totally clear; I am looking to change all layer colors to bylayer

Thank you

Mark

kpblc

  • Bull Frog
  • Posts: 396
Re: All Layers to ByLayer
« Reply #4 on: August 16, 2007, 01:49:58 PM »
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.
« Last Edit: August 16, 2007, 01:51:13 PM by kpblc »
Sorry for my English.

ML

  • Guest
Re: All Layers to ByLayer
« Reply #5 on: August 16, 2007, 01:59:55 PM »

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

Guest

  • Guest
Re: All Layers to ByLayer
« Reply #6 on: August 16, 2007, 02:06:36 PM »
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).   ^-^

ML

  • Guest
Re: All Layers to ByLayer
« Reply #7 on: August 16, 2007, 02:42:58 PM »

I am using 2006 and it doesn't exist in there :(

I tried this little bit of code:

Code: [Select]
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

ML

  • Guest
Re: All Layers to ByLayer
« Reply #8 on: August 16, 2007, 02:43:34 PM »

But it is still not working

deegeecees

  • Guest
Re: All Layers to ByLayer
« Reply #9 on: August 16, 2007, 02:47:26 PM »
Non-programmatic way:
Select all objects, then in the properties dialog, select "Color", "ByLayer".

ML

  • Guest
Re: All Layers to ByLayer
« Reply #10 on: August 16, 2007, 02:47:58 PM »

BOOOO!

You are no fun  LOL :)

Guest

  • Guest
Re: All Layers to ByLayer
« Reply #11 on: August 16, 2007, 02:48:22 PM »
Try this.... (or use what DGCs suggests)

Code: [Select]
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

deegeecees

  • Guest
Re: All Layers to ByLayer
« Reply #12 on: August 16, 2007, 02:48:57 PM »
I know, sometimes I feel like a wet blanket.

 :-)

ML

  • Guest
Re: All Layers to ByLayer
« Reply #13 on: August 16, 2007, 02:55:43 PM »

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

deegeecees

  • Guest
Re: All Layers to ByLayer
« Reply #14 on: August 16, 2007, 03:03:26 PM »
Matts code is what you need then.