- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- <CommandMethod("TlsSB")> Public Shared Sub TlsSelectionSetBreak()
- Dim pTM As New TlsTM
- Dim obj, pnt As Object
- pTM.StartTrans()
- Try
- Dim pId As ObjectId
- Dim pLength As Double
- Dim pCurve As Curve
- Dim pnts As New Point3dCollection
- Dim i As Curve
- pTM.OpenBlockTableRecord(BlockTableRecord.ModelSpace)
- pTM.Utility.GetEntity(obj, pnt)
- pId.OldId = obj.ObjectId
- pCurve = pId.Open(OpenMode.ForNotify, False, True)
- pLength = pCurve.GetDistAtPoint(pCurve.EndPoint)
- pnts.Add(pCurve.GetPointAtDist(pLength / 4))
- pnts.Add(pCurve.GetPointAtDist(pLength / 2))
- pnts.Add(pCurve.GetPointAtDist(pLength * 3 / 4))
- pCurve.GetSplitCurves(pnts)
- For Each i In pCurve.GetSplitCurves(pnts)
- pTM.AddEntity(i)
- Next
- pCurve.Close()
- pTM.CommitTrans()
- Catch ex As Exception
- MsgBox(ex.Message)
- Finally
- pTM.Dispose()
- End Try
- End Sub
- Imports Autodesk.AutoCAD.ApplicationServices
- Imports Autodesk.AutoCAD.DatabaseServices
- Imports Autodesk.AutoCAD.Runtime
- Imports Autodesk.AutoCAD.Interop
- Imports Autodesk.AutoCAD.Geometry
- Imports AutoCadTM = Autodesk.AutoCAD.DatabaseServices.TransactionManager Public Class TlsTM
- Private pDatabase As Database
- Private pTransactionManager As AutoCadTM
- Private pStartTransaction As Transaction
- Private pBlockTable As BlockTable
- Private pBlockTableRecord As BlockTableRecord '程序功能:向当前块表记录中加入实体
- Public Function AddEntity(ByVal TlsEntity As DBObject) pBlockTableRecord.AppendEntity(TlsEntity)
- pTransactionManager.AddNewlyCreatedDBObject(TlsEntity, True) End Function '程序功能:向当前块表记录中加入实体数组
- Public Function AddEntity(ByVal TlsEntity As DBObject()) Dim i As DBObject For Each i In TlsEntity pBlockTableRecord.AppendEntity(i)
- pTransactionManager.AddNewlyCreatedDBObject(i, True) Next i End Function '程序功能:生成一个新块,并加入实体
- Public Function AddBlock(ByVal Name As String, ByVal Entitys As DBObject()) As ObjectId
- Dim i As DBObject
- Dim pDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database
- Dim pTransactionManager As AutoCadTM = pDatabase.TransactionManager
- Dim pStartTransaction As Transaction = pTransactionManager.StartTransaction()
- Try Dim pBlockTable As BlockTable = CType(pTransactionManager.GetObject(pDatabase.BlockTableId, OpenMode.ForWrite, False), BlockTable)
- Dim pBlockTableRecord As New BlockTableRecord
- pBlockTableRecord.Name = Name
- pBlockTable.Add(pBlockTableRecord)
- Dim pId As ObjectId = pBlockTableRecord.Id For Each i In Entitys
- pBlockTableRecord.AppendEntity(i)
- pTransactionManager.AddNewlyCreatedDBObject(i, True)
- Next i pBlockTableRecord.Close()
- pBlockTable.Close()
- pStartTransaction.Commit() Return pId Finally pStartTransaction.Dispose() End Try End Function '开始事务
- Public Sub StartTrans() pDatabase = Application.DocumentManager.MdiActiveDocument.Database
- pTransactionManager = pDatabase.TransactionManager
- pStartTransaction = pTransactionManager.StartTransaction() End Sub '打开一个块表记录
- Public Sub OpenBlockTableRecord(ByVal str As String) pBlockTable = CType(pTransactionManager.GetObject(pDatabase.BlockTableId, OpenMode.ForRead, False), BlockTable)
- pBlockTableRecord = CType(pTransactionManager.GetObject(pBlockTable(str), OpenMode.ForWrite, False), BlockTableRecord) End Sub '事务提交
- Public Sub CommitTrans() pBlockTableRecord.Close()
- pBlockTable.Close() pStartTransaction.Commit() End Sub '事务结束
- Public Sub Dispose() pStartTransaction.Dispose()
- pBlockTableRecord = Nothing
- pBlockTable = Nothing
- pStartTransaction = Nothing
- pTransactionManager = Nothing
- pDatabase = Nothing End Sub
- '获取当前的辅助工具
- Public Function Utility() As AcadUtility Return Application.AcadApplication.ActiveDocument.Utility End Function
- Public Function AddLine(ByVal pointer1() As Double, ByVal pointer2() As Double) As Line Dim pLine As Line pLine = New Line( _
- New Point3d(pointer1(0), pointer1(1), pointer1(2)), _
- New Point3d(pointer2(0), pointer2(1), pointer2(2))) AddEntity(pLine) Return pLine End FunctionEnd Class
上述代码四分曲线后,如何将原实体删除?如果用obj.Delete()倒是可行,但不是正规的Arx方法 |
|