To catch all layer that have a Center lintype

To catch all layer that have a Center lintype

ace_guru
Advocate Advocate
371 Views
1 Reply
Message 1 of 2

To catch all layer that have a Center lintype

ace_guru
Advocate
Advocate

G'day Folks,

 

I'm trying to write a rountine which helps cleanup externally supplied drawings/block so they can suit our internal system. Currently I'm stuck on being able to select all layers which have a "Center" linetype. I can catch everything where the layers have linetype = "Center". But I can't catch the layers where the linetype = "ByLayer". Hope that makes some sort of sense.

 

Below is part of the code which tries to do the above...

 

Sub ChangeAllToLyer()
    Dim ssAll As AcadSelectionSet, mEntity As AcadEntity
    Dim Cnt As Integer
    Dim lTyp As String
    
    Set ssAll = ThisDrawing.SelectionSets.Add("AllEntities")
    'ThisDrawing.SelectionSets("allentites").Delete
    
    ssAll.Select acSelectionSetAll
    'Cnt = ssAll.Cnt
    'Debug.Print Cnt
    For Each mEntity In ssAll
        lTyp = mEntity.Linetype
        'Debug.Print lTyp
        'If mEntity.Linetype = "CENTER" Then
        If UCase(lTyp) = UCase("Center") Then
            mEntity.Layer = "4cl"
            mEntity.Color = acByLayer
        End If
    Next
    ssAll.Clear
    ssAll.Delete
    Set ssAll = Nothing
End Sub

 Also attached is a sample drawing that I've moocked up so I can see what gets updated. In theory, every layer which has a center type linetype should change to 4cl & cyan.

 

0 Likes
372 Views
1 Reply
Reply (1)
Message 2 of 2

norman.yuan
Mentor
Mentor

It seems that your post's title should be "To catch all entities that have "Center" linetype".

 

Anyways, "ByLayer" means that propery (LineType, Color,...) of an Entity is determined by the layer it resides. Therefore, you simply trace back to the layer to get the concrete value of the property. In your case, you do:

 

Dim isCenter As Boolean

Dim layer As AcadLayer

For Each mEntity In ssAll

 

  lType=UCase(mEntity.LineType)

  isCenter=False

 

  If lType="CENTER" Then

    IsCenter=True

  ElseIf lType="BYLAYER" Then

    set layer=ThisDrawing.Layers(mEntity.Layer)

    If UCase(layer.LineType)="CENTER" Then

      IsCenter=True

    End If

  End If

 

  If IsCenter Then

    ''Do whatever you need to here

  End If

 

Next

    

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes