Determine if layer already exists

Determine if layer already exists

Anonymous
Not applicable
1,858 Views
4 Replies
Message 1 of 5

Determine if layer already exists

Anonymous
Not applicable
Is there an equivalent to tblsearch in VBA for Autocad. If the layer exists I need to change some properties of it.

Thanks
0 Likes
1,859 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
This should do the trick:

Sub test()
Dim a
a = DoesLyrExist("0")
End Sub
Private Function DoesLyrExist(ByVal sLyrName As String) As Boolean
Dim acLyrs As AcadLayers
Dim iCnt As Integer

Set acLyrs = ThisDrawing.Layers
For iCnt = 0 To acLyrs.Count
If acLyrs(iCnt).Name = sLyrName Then
DoesLyrExist = True
Exit For
End If
Next iCnt

End Function

JR
0 Likes
Message 3 of 5

Anonymous
Not applicable
Collections usually offer direct access to their members, so why not take
advantage of it?

Public Function LayerExists(layerName As String) As Boolean

Dim layer As AcadLayer
On Error Resume Next
Set layer = ThisDrawing.Layers(layerName)
LayerExists = (Err.Number = 0)

End Function

--
Learn to think outside the book.

http://www.acadx.com
Message 4 of 5

Anonymous
Not applicable
Thanks so much. Worked grest.
0 Likes
Message 5 of 5

Anonymous
Not applicable
Yeah,
thanks Frank.

JR
0 Likes