Public Function LayerCreate(ByRef oDb As Database, _
ByRef oTransMan As DatabaseServices.TransactionManager, _
ByVal strName As String) As Boolean
' Open a transaction so we can modify the drawing
Dim oTrans As Transaction = oTransMan.StartTransaction()
' Set our return value to nothing
Dim retVal As Boolean = False
Try
' Check to see if the layer layer exists
If LayerExists(oDb, oTrans, strName) = False Then
' The layer doesn't exist so make a new one
Dim oLayer As LayerTableRecord = New LayerTableRecord
' Set the layer's name
oLayer.Name = strName
' Open up the layer table (for writing)
Dim oLayerTable As LayerTable = CType(oTransMan.GetObject(oDb.LayerTableId, _
OpenMode.ForWrite, _
False), _
LayerTable)
' Add the new layer to the layer table
oLayerTable.Add(oLayer)
' Add the line object to the drawing database
oTrans.AddNewlyCreatedDBObject(oLayer, True)
' Close the open transaction (very important)
oTrans.Commit()
End If
retVal = True
Catch ex As Runtime.Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Error in LayerCreate")
Finally
' Clean up the transaction object (very important)
oTrans.Dispose()
End Try
Return retVal
End Function
Keep in mind that this is a VERY simple layer routine. If this is all you use, all your layers will be white, continuous and have the default width. I'll leave it up to you to add in the extra features. Hint: do it before the oLayerTable.Add(oLayer) line.
No comments:
Post a Comment