It is a very wise idea to only have one open transaction at any time so most of the functions I post from now on will accept a transaction or a database object, among other things, as arguments.
Finding the current layer's name:
Public Function GetCurrentLayerName(ByRef oDb As Database, _
ByRef oTrans As Transaction) As String
' Create a layer object
Dim oLayer As DatabaseServices.LayerTableRecord
' Set our return value to nothing
Dim retVal As String = Nothing
Try
' Check if the layer exists...
oLayer = CType(oTrans.GetObject(oDb.Clayer, OpenMode.ForRead), LayerTableRecord)
' Return the current layer name
retVal = oLayer.Name
Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Error in GetCurrentLayerName")
End Try
Return retVal
End Function
Passing in the active database object and a transaction object, oDb.Clayer returns the current layer's object id so we need to do a GetObject on it to return the actual layer entity. Once we have it we simply check the name property.
No comments:
Post a Comment