曲线打断 显示曲线分段首尾坐标正确,CAD图面没变化?
Public Shared Sub xj_trim(ByVal PL As Polyline)Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Using trans As Transaction = db.TransactionManager.StartTransaction()
Dim p3dCOL As New Point3dCollection
p3dCOL = ModelSpace.getplCollection(PL) '获取线顶点集合
Dim res As PromptSelectionResult = ed.SelectFence(p3dCOL)
If res.Status <> PromptStatus.OK Then Exit Sub
Dim sset As SelectionSet = res.Value
Dim btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False)
For i As Integer = 0 To sset.Count - 1 '遍历
Dim fobj As FenceSelectedObject = sset(i)
Dim fent As Entity = trans.GetObject(fobj.ObjectId, OpenMode.ForWrite)
If TypeOf (fent) Is Curve Then
' //获取被栏选的直线和栏选点
Dim pCurve As Curve = trans.GetObject(fobj.ObjectId, OpenMode.ForWrite) '相交曲线
Dim ppd As Point3d = fobj.GetIntersectionPoints()(0).PointOnLine
pCurve.UpgradeOpen()
Dim P3C As New Point3dCollection
'//获取直线和偏移界线的交点集合
pCurve.IntersectWith(PL, Intersect.ExtendArgument, P3C, 0, 0) '获取交点集合
If P3C Is Nothing Then GoTo ii
Dim plist As New List(Of Double)
For Each pp As Point3d In P3C
plist.Add(pCurve.GetParameterAtPoint(pCurve.GetClosestPointTo(pp, False))) '获取交点最近点
Next
If (plist Is Nothing) Then GoTo ii
plist.Sort() '排序
Dim dcol As New DoubleCollection(plist.ToArray())
Try
For Each cc As Curve In pCurve.GetSplitCurves(dcol)'曲线打断
Debug.Print(cc.StartPoint.X & "," & cc.EndPoint.X) '显示曲线分段首尾x坐标完全正确
' 将图形对象的信息添加到块表记录中,
btr.AppendEntity(cc)
' 把图形对象添加到事务处理中.
trans.AddNewlyCreatedDBObject(cc, True)
Next
'pCurve.Erase()
Catch ex As Exception '出错
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace)
End Try
End If
ii: Next i
trans.Commit()
End Using
End Sub
点击曲线看看 曲线没变化,没有断开
显示曲线分段首尾坐标完全正确,但曲线没被打断
执行pCurve.Erase(),该曲线也删不掉
pCurve.Up...Open去掉
其他看不出什么大问题 pCurve.Up...Open去掉,也不行 我感觉没进行事务处理 请大侠帮忙看看 Debug.Print(cc.StartPoint.X & "," & cc.EndPoint.X) '显示曲线分段首尾x坐标完全正确
这里每个顶点画一个到 0 0 0的直线,看得到什么了?
去掉Try 结构会有什么错误呢? 我觉得可能是一个什么致命错误让过程退出了,让 trans.Commit()没有机会执行,所以把错误暴露出来分析下。
页:
[1]
2