明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3013|回复: 2

如何删除数据库实体?

[复制链接]
发表于 2004-10-1 13:53 | 显示全部楼层 |阅读模式
  1.        <CommandMethod("TlsSB")> Public Shared Sub TlsSelectionSetBreak()
  2.                Dim pTM As New TlsTM
  3.                Dim obj, pnt As Object
  4.                pTM.StartTrans()
  5.                Try
  6.                        Dim pId As ObjectId
  7.                        Dim pLength As Double
  8.                        Dim pCurve As Curve
  9.                        Dim pnts As New Point3dCollection
  10.                        Dim i As Curve
  11.                        pTM.OpenBlockTableRecord(BlockTableRecord.ModelSpace)
  12.                        pTM.Utility.GetEntity(obj, pnt)
  13.                        pId.OldId = obj.ObjectId
  14.                        pCurve = pId.Open(OpenMode.ForNotify, False, True)
  15.                        pLength = pCurve.GetDistAtPoint(pCurve.EndPoint)
  16.                        pnts.Add(pCurve.GetPointAtDist(pLength / 4))
  17.                        pnts.Add(pCurve.GetPointAtDist(pLength / 2))
  18.                        pnts.Add(pCurve.GetPointAtDist(pLength * 3 / 4))
  19.                        pCurve.GetSplitCurves(pnts)
  20.                        For Each i In pCurve.GetSplitCurves(pnts)
  21.                                pTM.AddEntity(i)
  22.                        Next
  23.                        pCurve.Close()
  24.                        pTM.CommitTrans()
  25.                Catch ex As Exception
  26.                        MsgBox(ex.Message)
  27.                Finally
  28.                        pTM.Dispose()
  29.                End Try
  30.        End Sub
  1.   
复制代码
  1. Imports Autodesk.AutoCAD.ApplicationServices
  2. Imports Autodesk.AutoCAD.DatabaseServices
  3. Imports Autodesk.AutoCAD.Runtime
  4. Imports Autodesk.AutoCAD.Interop
  5. Imports Autodesk.AutoCAD.Geometry
  6. Imports AutoCadTM = Autodesk.AutoCAD.DatabaseServices.TransactionManager Public Class TlsTM
  7.        Private pDatabase As Database
  8.        Private pTransactionManager As AutoCadTM
  9.        Private pStartTransaction As Transaction
  10.        Private pBlockTable As BlockTable
  11.        Private pBlockTableRecord As BlockTableRecord       '程序功能:向当前块表记录中加入实体
  12.        Public Function AddEntity(ByVal TlsEntity As DBObject)               pBlockTableRecord.AppendEntity(TlsEntity)
  13.                pTransactionManager.AddNewlyCreatedDBObject(TlsEntity, True)       End Function       '程序功能:向当前块表记录中加入实体数组
  14.        Public Function AddEntity(ByVal TlsEntity As DBObject())               Dim i As DBObject               For Each i In TlsEntity                       pBlockTableRecord.AppendEntity(i)
  15.                        pTransactionManager.AddNewlyCreatedDBObject(i, True)               Next i       End Function       '程序功能:生成一个新块,并加入实体
  16.        Public Function AddBlock(ByVal Name As String, ByVal Entitys As DBObject()) As ObjectId
  17.                Dim i As DBObject
  18.                Dim pDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database
  19.                Dim pTransactionManager As AutoCadTM = pDatabase.TransactionManager
  20.                Dim pStartTransaction As Transaction = pTransactionManager.StartTransaction()
  21.                Try                       Dim pBlockTable As BlockTable = CType(pTransactionManager.GetObject(pDatabase.BlockTableId, OpenMode.ForWrite, False), BlockTable)
  22.                        Dim pBlockTableRecord As New BlockTableRecord
  23.                        pBlockTableRecord.Name = Name
  24.                        pBlockTable.Add(pBlockTableRecord)
  25.                        Dim pId As ObjectId = pBlockTableRecord.Id                       For Each i In Entitys
  26.                                pBlockTableRecord.AppendEntity(i)
  27.                                pTransactionManager.AddNewlyCreatedDBObject(i, True)
  28.                        Next i                       pBlockTableRecord.Close()
  29.                        pBlockTable.Close()
  30.                        pStartTransaction.Commit()                       Return pId               Finally                       pStartTransaction.Dispose()               End Try       End Function       '开始事务
  31.        Public Sub StartTrans()               pDatabase = Application.DocumentManager.MdiActiveDocument.Database
  32.                pTransactionManager = pDatabase.TransactionManager
  33.                pStartTransaction = pTransactionManager.StartTransaction()       End Sub       '打开一个块表记录
  34.        Public Sub OpenBlockTableRecord(ByVal str As String)               pBlockTable = CType(pTransactionManager.GetObject(pDatabase.BlockTableId, OpenMode.ForRead, False), BlockTable)
  35.                pBlockTableRecord = CType(pTransactionManager.GetObject(pBlockTable(str), OpenMode.ForWrite, False), BlockTableRecord)       End Sub       '事务提交
  36.        Public Sub CommitTrans()               pBlockTableRecord.Close()
  37.                pBlockTable.Close()               pStartTransaction.Commit()       End Sub       '事务结束
  38.        Public Sub Dispose()               pStartTransaction.Dispose()
  39.                pBlockTableRecord = Nothing
  40.                pBlockTable = Nothing
  41.                pStartTransaction = Nothing
  42.                pTransactionManager = Nothing
  43.                pDatabase = Nothing       End Sub
  44.        '获取当前的辅助工具
  45.        Public Function Utility() As AcadUtility               Return Application.AcadApplication.ActiveDocument.Utility       End Function
  46.        Public Function AddLine(ByVal pointer1() As Double, ByVal pointer2() As Double) As Line               Dim pLine As Line               pLine = New Line( _
  47.                                        New Point3d(pointer1(0), pointer1(1), pointer1(2)), _
  48.                                        New Point3d(pointer2(0), pointer2(1), pointer2(2)))               AddEntity(pLine)               Return pLine       End FunctionEnd Class
上述代码四分曲线后,如何将原实体删除?如果用obj.Delete()倒是可行,但不是正规的Arx方法
发表于 2004-10-1 21:38 | 显示全部楼层
试一下Entity类从DBObject类继承来的Erase方法。
 楼主| 发表于 2004-10-2 14:55 | 显示全部楼层
用过Erase方法,总是出错,晕了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 07:30 , Processed in 0.299605 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表