Author Topic: Trouble with TraceBoundary After PromptStatus.Cancel  (Read 2331 times)

0 Members and 1 Guest are viewing this topic.

huaxiamengqing

  • Guest
Trouble with TraceBoundary After PromptStatus.Cancel
« on: July 23, 2018, 10:51:49 AM »
Hi, Dear all.

 I have a trouble with traceboundary function.

I use code to let user input points  to get the boundaries by traceboundary function. But I allways get nothing by this function after user input  ESC when get points. The cad says that "No objects can be found on the screen"

  See code below
Code: [Select]
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
You will always get  0 count dbs. But if I replace the TraceBoundary function into the  loop. It works well

see code below
Code: [Select]
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

That's really confused me. How anyone can give some suggestion.Thank you very much.

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Trouble with TraceBoundary After PromptStatus.Cancel
« Reply #1 on: July 23, 2018, 02:42:14 PM »
Just as a test edit your first example by pulling out of the loop
Code - Visual Basic: [Select]
  1. Dim selectpt As Point3d = Point3d.Origin
  2.  

then change
Code - Visual Basic: [Select]
  1. Dim dbs As DBObjectCollection = ed.TraceBoundary(rtpts.First, True)
  2.  
to
Code - Visual Basic: [Select]
  1. Dim dbs As DBObjectCollection = ed.TraceBoundary(selectpt, True)
  2.  

huaxiamengqing

  • Guest
Re: Trouble with TraceBoundary After PromptStatus.Cancel
« Reply #2 on: July 23, 2018, 08:37:34 PM »
Just as a test edit your first example by pulling out of the loop
Code - Visual Basic: [Select]
  1. Dim selectpt As Point3d = Point3d.Origin
  2.  

then change
Code - Visual Basic: [Select]
  1. Dim dbs As DBObjectCollection = ed.TraceBoundary(rtpts.First, True)
  2.  
to
Code - Visual Basic: [Select]
  1. Dim dbs As DBObjectCollection = ed.TraceBoundary(selectpt, True)
  2.  

Yes if you select one point not exit do by ESC, you will get the correct boundary.
But if you select more than one point and exit do by esc,psr.Status = PromptStatus.Cance, You will get nothing--!
That's really confused me these days