Sort Layers and Linetypes

AutoCAD ActiveX

 
Sort Layers and Linetypes
 
 
 

You can iterate through the Layers and Linetypes collections to find all the layers and linetypes in a drawing.

Iterate through the Layers collection

The following code iterates through the Layers collection to gather the names of all the layers in the drawing. The names are then displayed in a message box.

Sub Ch4_IteratingLayers()
    Dim layerNames As String
    Dim entry As AcadLayer
    layerNames = ""
    For Each entry In ThisDrawing.Layers
        layerNames = layerNames + entry.Name + vbCrLf
    Next
    MsgBox "The layers in this drawing are: " + _
 vbCrLf + layerNames
End Sub