Author Topic: Convert all to BYLAYER  (Read 9792 times)

0 Members and 1 Guest are viewing this topic.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Convert all to BYLAYER
« Reply #15 on: February 01, 2006, 02:36:46 PM »
I updated this code to reflect your last post
Code: [Select]
Private Sub SETCOLORLINETYPE()

Dim objLayer As AcadLayer
Dim objSelected As Object
Dim OBJSELSET As AcadSelectionSet
Dim n As Integer
Dim strLinetype As String
Dim strLayer As String

    If ThisDrawing.SelectionSets.Count > 0 Then
        For n = 0 To ThisDrawing.SelectionSets.Count - 1
            If ThisDrawing.SelectionSets.Item(n).Name = "ChangeLine" Then
                ThisDrawing.SelectionSets("ChangeLine").Delete
            End If
        Next n
    End If

    Set OBJSELSET = ThisDrawing.SelectionSets.Add("ChangeLine")
    OBJSELSET.Select acSelectionSetAll

    For Each objSelected In OBJSELSET
strLinetype = ThisDrawing.Layers(objSelected.Layer).Linetype

objSelected.Linetype = strLinetype
objSelected.color = acByLayer  ' I ADDED IT HERE
    Next
ThisDrawing.SelectionSets("ChangeLine").Delete
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: Convert all to BYLAYER
« Reply #16 on: February 01, 2006, 02:37:45 PM »
This is everything I have so far

Code: [Select]
Option Explicit

Public Sub FIXLAYERS()
    Call DELETELAYERS
    Call SETUPLAYERS
    Call SETCOLORLINETYPE
    Call CHANGELAYER
End Sub


Private Sub DELETELAYERS()
Dim objLayer As AcadLayer
Dim objSelected As Object
Dim OBJSELSET As AcadSelectionSet
Dim n As Integer
    ThisDrawing.ActiveLayer = ThisDrawing.Layers("0")
    For Each objLayer In ThisDrawing.Layers
        If objLayer.Name = "0" Then
            objLayer.Lock = False
            objLayer.LayerOn = True
            'objLayer.Freeze = False
        Else
            objLayer.Lock = False
        End If
    Next
    ThisDrawing.ActiveLayer = ThisDrawing.Layers("0")
    ThisDrawing.Application.Update
    ThisDrawing.Regen acAllViewports

    For Each objLayer In ThisDrawing.Layers
        If objLayer.LayerOn = False Then
            If ThisDrawing.SelectionSets.Count > 0 Then
                For n = 0 To ThisDrawing.SelectionSets.Count - 1
                    If ThisDrawing.SelectionSets.Item(n).Name = "layerdelete" Then
                        ThisDrawing.SelectionSets("layerdelete").Delete
                    End If
                Next n
            End If

            Set OBJSELSET = ThisDrawing.SelectionSets.Add("layerdelete")
            OBJSELSET.Select acSelectionSetAll

            For Each objSelected In OBJSELSET
                If objSelected.Layer = objLayer.Name Then
                    objSelected.Delete
                End If
            Next


            objLayer.Delete
        End If
    Next
    ThisDrawing.SelectionSets("layerdelete").Delete

    For Each objLayer In ThisDrawing.Layers
        If objLayer.Freeze = True Then
            If ThisDrawing.SelectionSets.Count > 0 Then
                For n = 0 To ThisDrawing.SelectionSets.Count - 1
                    If ThisDrawing.SelectionSets.Item(n).Name = "layerdelete" Then
                        ThisDrawing.SelectionSets("layerdelete").Delete
                    End If
                Next n
            End If

            Set OBJSELSET = ThisDrawing.SelectionSets.Add("layerdelete")
            OBJSELSET.Select acSelectionSetAll

            For Each objSelected In OBJSELSET
                If objSelected.Layer = objLayer.Name Then
                    objSelected.Delete
                End If
            Next


            objLayer.Delete
        End If
    Next

End Sub

Private Sub SETUPLAYERS()
Dim objLay As AcadLayer
    Set objLay = ThisDrawing.Layers.Add("E-BASE-PLAN")
    objLay.color = 252
End Sub

Private Sub SETCOLORLINETYPE()

Dim objLayer As AcadLayer
Dim objSelected As Object
Dim OBJSELSET As AcadSelectionSet
Dim n As Integer
Dim strLinetype As String
Dim strLayer As String

    If ThisDrawing.SelectionSets.Count > 0 Then
        For n = 0 To ThisDrawing.SelectionSets.Count - 1
            If ThisDrawing.SelectionSets.Item(n).Name = "ChangeLine" Then
                ThisDrawing.SelectionSets("ChangeLine").Delete
            End If
        Next n
    End If

    Set OBJSELSET = ThisDrawing.SelectionSets.Add("ChangeLine")
    OBJSELSET.Select acSelectionSetAll

    For Each objSelected In OBJSELSET
        strLinetype = ThisDrawing.Layers(objSelected.Layer).Linetype

        objSelected.Linetype = strLinetype
        objSelected.color = acByLayer  ' I ADDED IT HERE
    Next
    ThisDrawing.SelectionSets("ChangeLine").Delete
End Sub

Private Sub CHANGELAYER()

Dim ENT As AcadEntity
    On Error Resume Next
    For Each ENT In ThisDrawing.ModelSpace
        ENT.Layer = "E-BASE-PLAN"

    Next ENT
    ThisDrawing.Regen acAllViewports
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

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
Re: Convert all to BYLAYER
« Reply #17 on: February 01, 2006, 03:17:55 PM »
for each layer in this drawing layers collection, if its turned OFF (layeron=false) , make a selection set of ALL, then for each obj in SS, if the obj.Layer = ObjLayer.name (The name of the turned off layer), delete the object, repeat for next obj. Then delete layer from DB
PMFJI, but.....It seems to me this is the absolute slowest way of accomplishing this task and the next (frozen layers).Creating and stepping through a selection set of everything in the drawing for every layer that is off and again for every layer that is frozen.....

Something like this makes far more sense to me......use it once and move on. You could also make the strFltr a gloabl variable for use in cycling blocks to remove any objects from them that may be on those layers (use of InStr or Like would work for this).
Code: [Select]
Sub Freeze_Off_Delete()
Dim strFltr As String
Dim oLayer As AcadLayer
Dim oSS As AcadSelectionSet
Dim oEnt As AcadEntity
Dim iCode(0) As Integer
Dim vData(0) As Variant

For Each oLayer In ThisDrawing.Layers
    If (oLayer.Freeze = True) Or (oLayer.LayerOn = False) Then
        If strFltr = "" Then
            strFltr = oLayer.Name
        Else
            strFltr = strFltr & "," & oLayer.Name
        End If
    End If
Next
On Local Error Resume Next
Set oSS = ThisDrawing.SelectionSets.Item("DeleteEm")
If Err.Number <> 0 Then
    Set oSS = ThisDrawing.SelectionSets.Add("DeleteEm")
    Err.Clear
End If
On Local Error GoTo 0
oSS.Clear
iCode(0) = 8: vData(0) = strFltr
oSS.Select acSelectionSetAll, , , iCode, vData
For Each oEnt In oSS
    oEnt.Delete
Next
oSS.Delete
End Sub

Just my $0.02....
Jeff

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Convert all to BYLAYER
« Reply #18 on: February 01, 2006, 03:21:34 PM »
PMFJI - ??

I threw it together, and hadn't gone back to optimize it yet
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

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
Re: Convert all to BYLAYER
« Reply #19 on: February 01, 2006, 03:32:33 PM »
PMFJI - ??

I threw it together, and hadn't gone back to optimize it yet
Pardon Me For Jumping In.......
Sorry, carry on..... :-) I just saw that explanation and felt obliged to comment, especially since it seems like Chuck is trying to learn from this.

* Jeff_M *back to lurk mode*

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Convert all to BYLAYER
« Reply #20 on: February 01, 2006, 03:35:00 PM »
By all means jump in, I could use the help
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

nivuahc

  • Guest
Re: Convert all to BYLAYER
« Reply #21 on: February 01, 2006, 03:44:48 PM »
Okay, a hypothetical situation:

Let's say I have a line that's set to layer "EXAMPLE" set to color "BYLAYER" and linetype "DASHED". However, I also have an arc set to layer "EXAMPLE" which is color "RED" and linetype "BYLAYER". And, on top of that, I have an ellipse set to layer "EXAMPLE" with color and linetype set to "BYBLOCK". And, to top all of that off, the layer "EXAMPLE" has a linetype of "HIDDEN".

In the code posted so far, what will happen to those entities? Specifically, what will happen to those set to "BYLAYER" or "BYBLOCK"?

for each layer in this drawing layers collection, if its turned OFF (layeron=false) , make a selection set of ALL, then for each obj in SS, if the obj.Layer = ObjLayer.name (The name of the turned off layer), delete the object, repeat for next obj. Then delete layer from DB
PMFJI, but.....It seems to me this is the absolute slowest way of accomplishing this task and the next (frozen layers).Creating and stepping through a selection set of everything in the drawing for every layer that is off and again for every layer that is frozen.....

I thought the same thing when I looked at the code... partly why I was confused... but I was (and still am) willing to see where this is headed :)

...I just saw that explanation and felt obliged to comment, especially since it seems like Chuck is trying to learn from this.

* Jeff_M *back to lurk mode*

NO LURKING ALLOWED!   ;-)

The more the merrier, I always say  :-)

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Convert all to BYLAYER
« Reply #22 on: February 01, 2006, 03:48:35 PM »
based on previous posts, I set each entity to the linetype of the layer they were on, even if it was continuous.  Based on another comment, I added the color bylayer piece.  Did I miss understand?
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: Convert all to BYLAYER
« Reply #23 on: February 01, 2006, 03:51:05 PM »
Let's say I have a line that's set to layer "EXAMPLE" set to color "BYLAYER" and linetype "DASHED". However, I also have an arc set to layer "EXAMPLE" which is color "RED" and linetype "BYLAYER". And, on top of that, I have an ellipse set to layer "EXAMPLE" with color and linetype set to "BYBLOCK". And, to top all of that off, the layer "EXAMPLE" has a linetype of "HIDDEN".
As far as I know, everything will be assigned Hidden (From the layer Example) AND it just hit me B/T the eyes, you wanted everything that was bylayer to be assigned, and everything that was hardcoded (for lack of better term) to stay that way.

closer?
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

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
Re: Convert all to BYLAYER
« Reply #24 on: February 01, 2006, 04:02:29 PM »
<*HeadsUp*>
Before you all run into something unexpected, as did I when I was writing a similar routine a few months ago, your VBA application will up & die (or at least puke heavily) if it encounters any RTEXT objects. I worked around this by using a selectionset function in my calling lisp wrapper that either deletes or explodes ,with the command line version, the RTEXT.</*HeadsUp*>


nivuahc

  • Guest
Re: Convert all to BYLAYER
« Reply #25 on: February 01, 2006, 04:08:45 PM »
Using my hypothetical:

Each entity would be set as such
(Entity - Color - Linetype)

Code: [Select]
line    - ByLayer - DASHED
arc     - ByLayer - HIDDEN
ellipse - ByLayer - HIDDEN***

*** - Now this is where it gets tricky (at least I think so)... BYBLOCK

If it's a nested entity (let's say that ellipse is actually part of a block) then the the linetype would depend entirely on the linetype assigned to the block that it's a part of. So maybe it would be best to leave those entities as "BYBLOCK" as far as the linetype is concerned. But what if it's not a nested entity?

Maybe I'm just thinking too hard and I'm making this seem (to me) to be more difficult than it really is.

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
Re: Convert all to BYLAYER
« Reply #26 on: February 01, 2006, 04:14:15 PM »
It seems to me that if an object has a linetype, or color, of BYBLOCK then it should be an object IN a block and should be left alone. If it is an object that is actually in Modelspace, then it should take on the properties of the layer it is on......

nivuahc

  • Guest
Re: Convert all to BYLAYER
« Reply #27 on: February 01, 2006, 04:16:13 PM »
It seems to me that if an object has a linetype, or color, of BYBLOCK then it should be an object IN a block and should be left alone. If it is an object that is actually in Modelspace, then it should take on the properties of the layer it is on......

yeah, that makes the most sense.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: Convert all to BYLAYER
« Reply #28 on: February 01, 2006, 04:21:32 PM »
Jeff, feel free to jump in on the block conversion and attribute conversion, as I have never modified sub-entities.  I was kinda hoping someone would pick up from here and go with it.

Now, we agree that all entities are to be color bylayer right?
And, if an entity has a linetype assigned, it keeps that linetype, and moves to the new layer,
But if an entity is linetype bylayer, it gets assigned the linetype of the layer its on, and then moves to new layer?
does this make sense
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

nivuahc

  • Guest
Re: Convert all to BYLAYER
« Reply #29 on: February 01, 2006, 04:26:47 PM »
Jeff, feel free to jump in on the block conversion and attribute conversion, as I have never modified sub-entities.  I was kinda hoping someone would pick up from here and go with it.

Now, we agree that all entities are to be color bylayer right?
And, if an entity has a linetype assigned, it keeps that linetype, and moves to the new layer,
But if an entity is linetype bylayer, it gets assigned the linetype of the layer its on, and then moves to new layer?
does this make sense

Zackly :)