<CommandMethod("joinPline")> _
Public Shared Sub joinPolylines()
Dim pEntrs As PromptEntityResult
Dim peo1 As New PromptEntityOptions(vbLf & "Select source polyline : ")
peo1.SetRejectMessage(vbLf & "Invalid selection...")
peo1.AddAllowedClass(GetType(Polyline), True)
peo1.AddAllowedClass(GetType(Polyline2d), True)
peo1.AddAllowedClass(GetType(Polyline3d), True)
pEntrs = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(peo1)
If PromptStatus.OK <> pEntrs.Status Then
Return
End If
Dim srcId As ObjectId = pEntrs.ObjectId
Dim peo2 As New PromptEntityOptions(vbLf & "Select polyline to join : ")
peo2.SetRejectMessage(vbLf & "Invalid selection...")
peo2.AddAllowedClass(GetType(Polyline), True)
peo2.AddAllowedClass(GetType(Polyline2d), True)
peo2.AddAllowedClass(GetType(Polyline3d), True)
pEntrs = Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(peo2)
If PromptStatus.OK <> pEntrs.Status Then
Return
End If
Dim joinId As ObjectId = pEntrs.ObjectId
Dim trans As Transaction Is Nothing
Try
Using trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()
Dim srcPLine As Entity = TryCast(trans.GetObject(srcId, OpenMode.ForRead), Entity)
Dim addPLine As Entity = TryCast(trans.GetObject(joinId, OpenMode.ForRead), Entity)
srcPLine.UpgradeOpen()
srcPLine.JoinEntity(addPLine)
addPLine.UpgradeOpen()
addPLine.[Erase]()
trans.Commit()
End Using
Catch ex As System.Exception
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.Message)
End Try
End Sub