Document Change Event

Document Change Event

Anonymous
Not applicable
1,319 Views
4 Replies
Message 1 of 5

Document Change Event

Anonymous
Not applicable

Hi

 

How i can detect that an active document is changed and fire an event to notify.

 

thanks

 

0 Likes
1,320 Views
4 Replies
Replies (4)
Message 2 of 5

arcticad
Advisor
Advisor

 

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

 

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 5

Anonymous
Not applicable

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

 

0 Likes
Message 4 of 5

arcticad
Advisor
Advisor

 

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

 

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 5 of 5

Anonymous
Not applicable

thanks i will try that

0 Likes