Imports Autodesk.AutoCAD.ApplicationServices Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application Public Class VbExtApp Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Private DocMan As DocumentCollection 'Initialize sub Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize DocMan = AcApp.DocumentManager AddHandler DocMan.DocumentActivated, AddressOf callback_documentActivated AddHandler DocMan.DocumentCreated, AddressOf callback_documentCreated End Sub 'Terminate sub Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentActivated RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentCreated End Sub Private Sub callback_documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) If e.Document = Nothing Then Exit Sub Else MsgBox("Created") End If End Sub Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) If e.Document = Nothing Then Exit Sub Else MsgBox("Activated") End If End Sub End Class
thanks for your reply
but i am asking for if a document is active and i change some thing in drawing. how i can raise an event at that time.
for example i have a dwg and its active doc and i add a circle or remove a triangle from it how i can notify user that some thing has changed in the drawing.
thanks
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Imports AcApp = Autodesk.AutoCAD.ApplicationServices.Application Public Class VbExtApp Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Private DocMan As DocumentCollection Private db As Database 'Initialize sub Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize DocMan = AcApp.DocumentManager AddHandler DocMan.DocumentActivated, AddressOf callback_documentActivated AddHandler DocMan.DocumentCreated, AddressOf callback_documentCreated ' get First Open Drawing initEvents() End Sub Sub initEvents() For Each doc In DocMan Dim db As Database = doc.Database AddHandler db.ObjectAppended, AddressOf callback_ObjectAppended AddHandler db.ObjectErased, AddressOf callback_ObjectErased AddHandler db.ObjectModified, AddressOf callback_ObjectModified Next End Sub Private Sub callback_ObjectAppended(ByVal sender As Object, ByVal e As ObjectEventArgs) MsgBox(e.DBObject.ToString() & "-Appended") End Sub Private Sub callback_ObjectErased(ByVal sender As Object, ByVal e As ObjectErasedEventArgs) MsgBox(e.DBObject.ToString() & "-Erased") End Sub Private Sub callback_ObjectModified(ByVal sender As Object, ByVal e As ObjectEventArgs) MsgBox(e.DBObject.ToString() & "-Modified") End Sub 'Terminate sub Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentActivated RemoveHandler DocMan.DocumentCreated, AddressOf callback_documentCreated ' Not sure if this is needed RemoveHandler db.ObjectAppended, AddressOf callback_ObjectAppended RemoveHandler db.ObjectErased, AddressOf callback_ObjectErased RemoveHandler db.ObjectModified, AddressOf callback_ObjectModified End Sub Private Sub callback_documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) initEvents() End Sub Private Sub callback_documentActivated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) initEvents() End Sub End Class
thanks i will try that