Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Namespace ManagedApplication
Class TlsApplication
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
TTest.Start()
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
End Sub
End Class
Class TTest
Public Shared Sub Start()
AddHandler Application.DocumentManager.DocumentCreated, New DocumentCollectionEventHandler(AddressOf documentCreated)
End Sub
Shared Sub documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
Dim doc As Document = e.Document
Dim db As Database = doc.Database
Dim s As String = ""
Dim tr As Transaction = db.TransactionManager.StartTransaction()
doc.Editor.WriteMessage("111")
Using tr
Dim bt As BlockTable = CType(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
Dim btr As BlockTableRecord = CType(tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForRead), BlockTableRecord)
Dim id As ObjectId
For Each id In btr
Dim ent As Entity = CType(tr.GetObject(id, OpenMode.ForRead), Entity)
s += "\n" + ent.GetType().Name
doc.Editor.WriteMessage(s)
Next
End Using
End Sub
End Class
End Namespace