Hello,
Can somebody please tell me why I am getting a "FATAL ERROR" in Autocad 2008 at the
"curve.Explode(xobjs)" line? If I leave the explode section out it works fine.
Thanks!
Public Sub Test()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim db As Database = Application.DocumentManager.MdiActiveDocument.Database
Dim trans As Transaction = db.TransactionManager.StartTransaction()
Dim curves_p As DBObjectCollection = Nothing
Dim curves_n As DBObjectCollection = Nothing
Dim xents As DBObjectCollection = Nothing
Dim xobjs As DBObjectCollection = Nothing
Try
Dim selOptions As PromptSelectionOptions = New PromptSelectionOptions
selOptions.MessageForAdding = "Select polyline(s) to offset:"
selOptions.AllowDuplicates = False
selOptions.SingleOnly = False
Dim result As PromptSelectionResult = ed.GetSelection(selOptions)
If result.Status <> PromptStatus.OK Then Return
Dim selSet As SelectionSet = result.Value
Dim dblOptions As New PromptDoubleOptions(ControlChars.Lf & "Enter offset: ")
dblOptions.AllowNegative = False
dblOptions.AllowNone = False
dblOptions.AllowZero = False
Dim dblOptionsResult As PromptDoubleResult = ed.GetDouble(dblOptions)
If dblOptionsResult.Status <> PromptStatus.OK Then Return
Dim offset As Double = dblOptionsResult.Value
Dim objIdArray As ObjectId() = selSet.GetObjectIds()
Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
Dim ent As Entity
Dim pl As Polyline
Dim xent As Entity
Dim id As ObjectId
For Each id In objIdArray
ent = DirectCast(trans.GetObject(id, OpenMode.ForRead), Entity)
pl = DirectCast(ent, Polyline)
curves_p = pl.GetOffsetCurves(offset) 'positive offset
curves_n = pl.GetOffsetCurves(-offset) 'negative offset
If curves_n IsNot Nothing Then
For Each curve As Entity In curves_n
curve.ColorIndex = 1
btr.AppendEntity(curve)
trans.AddNewlyCreatedDBObject(curve, True)
Next
End If
If curves_p IsNot Nothing Then
For Each curve As Entity In curves_p
curve.ColorIndex = 1
'Explode/
curve.Explode(xobjs)
For Each xobj As DBObject In xobjs
xent = DirectCast(xobj, Entity)
btr.AppendEntity(xent)
trans.AddNewlyCreatedDBObject(xent, True)
Next
'/Explode
'btr.AppendEntity(curve)
'trans.AddNewlyCreatedDBObject(curve, True)
Next
End If
Next id
trans.Commit()
curves_p.Dispose()
curves_n.Dispose()
Catch ex As Exception
trans.Abort()
MsgBox(ex.Message)
Finally
trans.Dispose()
End Try
End Sub
EDIT: by Dan ... added code tags