Public Function LayerExists(ByRef oDb As Database, _
ByRef oTrans As Transaction, _
ByVal strName As String) As Boolean
' Create a layer object
Dim oLayer As LayerTableRecord
' Set our return value to nothing
Dim retValue As Boolean = False
Try
' Open up the layer table (for reading)
Dim oLayerTable As LayerTable = CType(oTrans.GetObject(oDb.LayerTableId, _
OpenMode.ForRead, _
False), _
LayerTable)
' Loop through each object in the layer table
For Each objId As ObjectId In oLayerTable
' Get the layertablerecord object for the current id
oLayer = CType(oTrans.GetObject(objId, _
OpenMode.ForWrite), _
LayerTableRecord)
' Compare the layer name to the strName variable and
' make sure we're not checking erased layers
If oLayer.Name.ToUpper.Equals(strName.ToUpper) And _
Not oLayer.IsErased Then
' Found the layer
retValue = True
Exit For
End If
Next
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error in LayerExists")
End Try
Return retValue
End Function
No comments:
Post a Comment