Public Sub ExtrudePline()
' Never dispose Document nor Document.Editor
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim ed As Editor = doc.Editor
' Never dispose Database when the drawing is opened in the Editor
' On the other hand, always dispose Database created with the constructor (i.e. New Database())
Dim db As Database = doc.Database
' Always dispose DocumentLock
Using doc.LockDocument()
' Always dispose Transaction
Using tr As Transaction = db.TransactionManager.StartTransaction()
' No need to dispose a DBObject opened from a transaction
Dim currentSpace As BlockTableRecord = _
DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
' Always dispose a new DBObject which may not be added to the database
Using pline As New Polyline()
pline.AddVertexAt(0, Point2d.Origin, 0.0, 0.0, 0.0)
pline.AddVertexAt(1, New Point2d(10.0, 0.0), 0.0, 0.0, 0.0)
pline.AddVertexAt(2, New Point2d(10.0, 10.0), 1.0, 0.0, 0.0)
pline.AddVertexAt(3, New Point2d(0.0, 10.0), 0.0, 0.0, 0.0)
pline.Closed = True
' Dispose DBObjectCollection in case there're some objects left
' for which no managed wrapper have been created
Using plineCollection As New DBObjectCollection()
plineCollection.Add(pline)
' Dispose DBObjectCollection in case there're some objects left
' for which no managed wrapper have been created
Using regionCollection As DBObjectCollection = _
Region.CreateFromCurves(plineCollection)
' Always dispose an object contained in a DBObjectCollection
' for which a managed wrapper is created and isn't added to the database
Using region As Region = DirectCast(regionCollection(0), Region)
' Use Dispose to insure the new DBObject will be disposed
' if an exception occurs before it is added to the Database
Using solid As New Solid3d()
solid.Extrude(region, 30.0, 0.0)
currentSpace.AppendEntity(solid)
tr.AddNewlyCreatedDBObject(solid, True)
End Using
End Using
End Using
End Using
If CShort(Application.GetSystemVariable("DELOBJ")) = 0 Then
currentSpace.AppendEntity(pline)
tr.AddNewlyCreatedDBObject(pline, True)
End If
End Using
tr.Commit()
End Using
End Using
End Sub