常用语句

1、当前活动文档   

 Dim doc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument

2、拾取图元

       Dim doc As ApplicationServices.Document = ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim peo As New EditorInput.PromptEntityOptions("请指定一个图块")
        With peo
            .SetRejectMessage("需要图块")
            .AddAllowedClass(GetType(DatabaseServices.BlockReference), True)
        End With

        Dim per As EditorInput.PromptEntityResult = doc.Editor.GetEntity(peo)

        If Not per.Status = EditorInput.PromptStatus.OK Then
            Exit Sub
        End If
View Code

 3、添加图元

 Using btr As BlockTableRecord = DirectCast(Tr.GetObject(doc.Database.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

    DIM1ID = btr.AppendEntity(ENT)  
End Using

Tr.AddNewlyCreatedDBObject(ENT, True)

 4、使用事物处理

Using dc As ApplicationServices.DocumentLock = doc.LockDocument()
            Using Db As DatabaseServices.Database = doc.Database
                Using Tr As DatabaseServices.Transaction = Db.TransactionManager.StartTransaction()



                End Using
            End Using
        End Using
View Code
原文地址:https://www.cnblogs.com/rf8862/p/13726229.html