明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2049|回复: 16

曲线打断 显示曲线分段首尾坐标正确,CAD图面没变化?

[复制链接]
发表于 2016-2-20 11:07 | 显示全部楼层 |阅读模式
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
发表于 2016-2-20 12:39 来自手机 | 显示全部楼层
点击曲线看看
 楼主| 发表于 2016-2-20 14:32 | 显示全部楼层
曲线没变化,没有断开
 楼主| 发表于 2016-2-20 14:38 | 显示全部楼层

显示曲线分段首尾坐标完全正确,但曲线没被打断
执行pCurve.Erase(),该曲线也删不掉
发表于 2016-2-20 15:06 来自手机 | 显示全部楼层
pCurve.Up...Open去掉
其他看不出什么大问题
 楼主| 发表于 2016-2-20 15:23 | 显示全部楼层
pCurve.Up...Open去掉,也不行
 楼主| 发表于 2016-2-20 15:24 | 显示全部楼层
我感觉没进行事务处理
 楼主| 发表于 2016-2-20 15:52 | 显示全部楼层
请大侠帮忙看看
发表于 2016-2-20 17:26 | 显示全部楼层
   Debug.Print(cc.StartPoint.X & "," & cc.EndPoint.X) '显示曲线分段首尾x坐标  完全正确
这里每个顶点画一个到 0 0 0的直线,看得到什么了?
去掉Try 结构会有什么错误呢?
发表于 2016-2-20 17:28 | 显示全部楼层
我觉得可能是一个什么致命错误让过程退出了,让 trans.Commit()没有机会执行,所以把错误暴露出来分析下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-25 14:24 , Processed in 3.985742 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表