huaxiamengqing 发表于 2018-7-23 10:51:49

TraceBoundaryPromptStatus.Cancel后的问题

嗨,亲爱的所有人。
我有一个与trace边界函数的麻烦。
我使用代码让用户输入点通过trace边界函数获取边界。但我总是通过这个函数在用户输入ESC获取点后一无所获。cad说“在屏幕上找不到任何对象”
见下面的代码
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
      Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database = acDoc.Database
      Dim ed As Editor = acDoc.Editor
      Dim cucs As Matrix3d = ed.CurrentUserCoordinateSystem
      ed.CurrentUserCoordinateSystem = Matrix3d.Identity
      Dim rtpts As New List(Of Point3d)
      Try
            Do
                ' System.Windows.Forms.Application.DoEvents()
                Dim Mpso As New PromptPointOptions(vbCr & "Insert Points")
                'Dim Mpso As New PromptPointOptions(vbCr & "编号插入点")
                Dim psr As PromptPointResult = ed.GetPoint(Mpso)
                Dim selectpt As Point3d = Point3d.Origin
                If psr.Status = PromptStatus.OK Then
                  selectpt = psr.Value
                  rtpts.Add(selectpt)
                Else
                  Exit Do
                End If
                '' Start a transaction
                'Using dblock As Autodesk.AutoCAD.ApplicationServices.DocumentLock = acDoc.LockDocument
                '    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                '      '' Open the Block table for read
                '      Dim acBlkTbl As BlockTable
                '      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                '                     OpenMode.ForRead)
                '      '' Open the Block table record Model space for write
                '      Dim acBlkTblRec As BlockTableRecord
                '      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace),
                '                        OpenMode.ForWrite)
                '      '' Create a single-line text object
                '      Stone.Layer.EnsureLayer("Stone_Points", 3)
                '      Using acPoint As DBPoint = New DBPoint()
                '            acPoint.Position = selectpt
                '            acPoint.Layer = "Stone_Points"
                '            acBlkTblRec.AppendEntity(acPoint)
                '            acTrans.AddNewlyCreatedDBObject(acPoint, True)
                '      End Using
                '      '' Save the changes and dispose of the transaction
                '      acTrans.Commit()
                '    End Using
                'End Using
            Loop
            Dim dbs As DBObjectCollection = ed.TraceBoundary(rtpts.First, True)
            MsgBox(dbs.Count.ToString)
      Catch ex As Exception
            ed.CurrentUserCoordinateSystem = cucs
   
      Finally
      End Try
      ed.CurrentUserCoordinateSystem = cucs

你总是会得到0 count dbs。但如果我将TraceBoundary函数替换为循环。它工作得很好
见下面的代码
dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
      Dim acCurDb As Autodesk.AutoCAD.DatabaseServices.Database = acDoc.Database
      Dim ed As Editor = acDoc.Editor
      Dim cucs As Matrix3d = ed.CurrentUserCoordinateSystem
      ed.CurrentUserCoordinateSystem = Matrix3d.Identity
      Dim rtpts As New List(Of Point3d)
      Try
            Do
                ' System.Windows.Forms.Application.DoEvents()
                Dim Mpso As New PromptPointOptions(vbCr & "Insert Points")
                'Dim Mpso As New PromptPointOptions(vbCr & "编号插入点")
                Dim psr As PromptPointResult = ed.GetPoint(Mpso)
                Dim selectpt As Point3d = Point3d.Origin
                If psr.Status = PromptStatus.OK Then
                  selectpt = psr.Value
                  Dim dbs As DBObjectCollection = ed.TraceBoundary(selectpt, True)
                  MsgBox(dbs.Count.ToString)
                  rtpts.Add(selectpt)
                Else
                  Exit Do
                End If
                '' Start a transaction
                'Using dblock As Autodesk.AutoCAD.ApplicationServices.DocumentLock = acDoc.LockDocument
                '    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                '      '' Open the Block table for read
                '      Dim acBlkTbl As BlockTable
                '      acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                '                     OpenMode.ForRead)
                '      '' Open the Block table record Model space for write
                '      Dim acBlkTblRec As BlockTableRecord
                '      acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace),
                '                        OpenMode.ForWrite)
                '      '' Create a single-line text object
                '      Stone.Layer.EnsureLayer("Stone_Points", 3)
                '      Using acPoint As DBPoint = New DBPoint()
                '            acPoint.Position = selectpt
                '            acPoint.Layer = "Stone_Points"
                '            acBlkTblRec.AppendEntity(acPoint)
                '            acTrans.AddNewlyCreatedDBObject(acPoint, True)
                '      End Using
                '      '' Save the changes and dispose of the transaction
                '      acTrans.Commit()
                '    End Using
                'End Using
            Loop
      Catch ex As Exception
            ed.CurrentUserCoordinateSystem = cucs
      Finally
      End Try
      ed.CurrentUserCoordinateSystem = cucs
那真的让我很困惑。怎么有人能给你一些非常suggestion.Thank。
**** Hidden Message *****

huaxiamengqing 发表于 2018-7-23 14:42:14

就像测试编辑你的第一个示例一样,通过拉出循环Dim selectpt As Point3d = Point3d.Origin。
then changeDim dbs As DBObjectCollection = ed.TraceBoundary(rtpts.首先,真实)。
toDim dbs As DBObjectCollection = ed.TraceBoundary(selectpt, True)。

huaxiamengqing 发表于 2018-7-23 20:37:34


是的,如果您选择一个点,而不是按ESC键退出,您将获得正确的边界。
但是如果您选择了多个点并按esc、psr退出do。Status = PromptStatus。取消,你将一无所获-!
这几天我真的很困惑
页: [1]
查看完整版本: TraceBoundaryPromptStatus.Cancel后的问题