- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 作者 于 2004-6-28 15:26:10 编辑
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 Module Module1
End Module
Public Class TlsTemp
<CommandMethod("test")> Public Shared Sub MytestCmd()
Dim pUtility As AcadUtility = Application.DocumentManager.MdiActiveDocument.AcadDocument.Utility Dim pT As New TlsDatabase Dim p1, p2 As Object
'在屏幕上选取两个点生成一条直线 p1 = pUtility.GetPoint() p2 = pUtility.GetPoint(p1) Dim pLine As New Line(New Point3d(p1(0), p1(1), p1(2)), New Point3d(p2(0), p2(1), p2(2))) pT.AppendEntity(pLine)
'生成一条直线,并加入到无名块,插入 Dim p As Object = pUtility.GetPoint() Dim pEs(0) As DBObject 'pEs(0) = New Line(New Point3d(p1(0), p1(1), p1(2)), New Point3d(p2(0), p2(1), p2(2))) pEs(0) = pLine.Clone Dim pBlock As ObjectId = pT.AppendBlock("*U", pEs) Dim pObj As New BlockReference(New Point3d(p(0), p(1), p(2)), pBlock) pT.AppendEntity(pObj)
End Sub
End Class Public Class TlsDatabase
'程序功能:向当前模型空间加入实体 Public Function AppendEntity(ByVal TlsEntity 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.ForRead, False), BlockTable) Dim pBlockTableRecord As BlockTableRecord = CType(pTransactionManager.GetObject(pBlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite, False), BlockTableRecord)
pBlockTableRecord.AppendEntity(TlsEntity) pTransactionManager.AddNewlyCreatedDBObject(TlsEntity, True)
pStartTransaction.Commit()
Finally
pStartTransaction.Dispose()
End Try
End Function
'程序功能:生成一个新块,并加入实体 Public Function AppendBlock(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() pStartTransaction.Commit()
Return pId
Finally
pStartTransaction.Dispose()
End Try
End Function
End Class |
|