嗨,亲爱的所有人。
我有一个与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。
本帖以下内容被隐藏保护;需要你回复后,才能看到! 游客,如果您要查看本帖隐藏内容请 回复 |