Author Topic: All Layers to ByLayer  (Read 3483 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: 330
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.

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: All Layers to ByLayer
« Reply #15 on: August 16, 2007, 03:03:47 PM »
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.

Guest

  • Guest
Re: All Layers to ByLayer
« Reply #16 on: August 16, 2007, 03:07:09 PM »
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:

deegeecees

  • Guest
Re: All Layers to ByLayer
« Reply #17 on: August 16, 2007, 03:07:16 PM »

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: All Layers to ByLayer
« Reply #18 on: August 16, 2007, 03:08:31 PM »
Here is what I use, modify to suit
Code: [Select]
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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: All Layers to ByLayer
« Reply #19 on: August 16, 2007, 03:10:02 PM »
This is worth a look
Wow, I forgot all about that!  Cool blast from the past, thanks DGCs
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: All Layers to ByLayer
« Reply #20 on: August 16, 2007, 03:12:35 PM »
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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Guest

  • Guest
Re: All Layers to ByLayer
« Reply #21 on: August 16, 2007, 03:13:35 PM »
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!

ML

  • Guest
Re: All Layers to ByLayer
« Reply #22 on: August 16, 2007, 03:18:41 PM »


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

ronjonp

  • Needs a day job
  • Posts: 7060
Re: All Layers to ByLayer
« Reply #23 on: August 16, 2007, 03:20:27 PM »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

Guest

  • Guest
Re: All Layers to ByLayer
« Reply #24 on: August 16, 2007, 03:25:21 PM »
Thanks Matt

You're welcome.


You got plenty of good solutions here, so use whatever works best for you.

ML

  • Guest
Re: All Layers to ByLayer
« Reply #25 on: August 16, 2007, 03:32:54 PM »

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

Bryco

  • Water Moccasin
  • Posts: 1850
Re: All Layers to ByLayer
« Reply #26 on: August 16, 2007, 11:30:26 PM »
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.