Message 1 of 5
Not applicable
11-14-2019
11:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to write a routine to check if then first point of a polyline en the last point is the same. If yes and polyline is not closed: delete last vertice and close polyline. My code crashes at
Dim obj As Object = myObjID.GetObject(OpenMode.ForRead, False)
when there are more than one polygons.
What is wrong.
In the next step I want to expand my code to all polylines (polyline3d, polyline2d, polyline and lwpolyline) : the code crashes also when I add this to the typed value
<CommandMethod("Closepolygons")>
Public Shared Sub Closepolygons()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim filterlist As TypedValue() = New TypedValue(1) {}
filterlist(0) = New TypedValue(0, "LWPOLYLINE")
filterlist(1) = New TypedValue(8, "*")
Dim filter As SelectionFilter = New SelectionFilter(filterlist)
Dim selRes As PromptSelectionResult = ed.SelectAll(filter)
Dim myObjIDs As ObjectIdCollection
If selRes.Status = PromptStatus.OK Then
' If per.Status = PromptStatus.OK Then
myObjIDs = New ObjectIdCollection(selRes.Value.GetObjectIds)
Dim tr As Transaction = db.TransactionManager.StartTransaction()
For Each myObjID In myObjIDs
Using tr
Dim obj As Object = myObjID.GetObject(OpenMode.ForRead, False)
Dim lwp As Polyline = TryCast(obj, Polyline)
If lwp IsNot Nothing Then
Dim vn As Integer = lwp.NumberOfVertices
Dim point1, point2 As Point2d
point1 = lwp.GetPoint2dAt(0)
point2 = lwp.GetPoint2dAt(vn - 1)
If point1 = point2 Then
'delete last vertex
Dim obj2 As Object = myObjID.GetObject(OpenMode.ForWrite, False)
lwp.RemoveVertexAt(vn - 1)
If Not lwp.Closed Then
lwp.Closed = True
End If
lwp.UpgradeOpen()
lwp.RecordGraphicsModified(True)
End If
End If
tr.Commit()
End Using
Next
End If
End Sub
Solved! Go to Solution.