Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I was testing to insert a vertex at a polyline using InsertVertexAt method. But it just crashes every time. Is there anything wrong? The code was copied from a vertex removal code. The removal worked fine. I then try to convert it to add a vertex just 10 units next to the index vertex and failed.
<CommandMethod("R3DV")> _
Public Shared Sub RemoveVertex()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using oTr As Transaction = db.TransactionManager.StartTransaction
Dim ids As New ObjectIdCollection
Dim options As New PromptEntityOptions(vbLf & "Pick a 3DPolyline:")
options.SetRejectMessage("Select 3DPolyline only" + vbLf)
options.AddAllowedClass(GetType(Polyline3d), True)
Dim result As PromptEntityResult = ed.GetEntity(options)
If result.Status <> PromptStatus.OK Then
Return
End If
' Polyline3D object
Dim oEnt As Polyline3d = TryCast(oTr.GetObject(result.ObjectId, OpenMode.ForRead), Polyline3d)
' Find each vertex in 3D Polyline
For Each oVtId As ObjectId In oEnt
Dim oVt As PolylineVertex3d = TryCast(oTr.GetObject(oVtId, OpenMode.ForRead), PolylineVertex3d)
Dim oPko As New PromptKeywordOptions(vbLf & "Want to remove vertex at " + oVt.Position.ToString() + "?")
oPko.AllowNone = False
oPko.Keywords.Add("Yes")
oPko.Keywords.Add("No")
oPko.Keywords.[Default] = "No"
Dim oPkr As PromptResult = ed.GetKeywords(oPko)
If oPkr.Status = PromptStatus.OK AndAlso oPkr.StringResult = "Yes" Then
ids.Add(oVtId) ' ids stores verteies object id's.
End If
Next
For Each oVtId As ObjectId In ids
Dim oVt As PolylineVertex3d = TryCast(oTr.GetObject(oVtId, OpenMode.ForWrite), PolylineVertex3d)
Dim nVtP3d As Point3d = New Point3d(oVt.Position.X + 10, oVt.Position.Y, oVt.Position.Z)
Dim nVt As PolylineVertex3d = New PolylineVertex3d(nVtP3d)
Try
oEnt.InsertVertexAt(oVt, nVt)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
MsgBox(ex.ToString)
End Try
'oVt.[Erase]()
Next
If ids.Count <> 0 Then
oEnt.UpgradeOpen() ' Upgrade open mode from readonly to write.
'oTr.AddNewlyCreatedDBObject(nVt, True)
oEnt.RecordGraphicsModified(True)
End If
oTr.Commit()
End Using
End Sub
Solved! Go to Solution.