VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

object_modified event and SAVE

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
456 Views, 3 Replies

object_modified event and SAVE

I have made a small VBA routine that uses object_modified event.

The routine work perfectly, but I have discovered that object_modified event is called in connection with the command SAVE.
In a drawing with approximately 1000 dynamic blocks object_modified event is called more than 10,000 times and the SAVE the command becomes very slow.
Is there a method in which one can avoid object_modified event is called - except to unload the .dvb in which object_modified event is called.

3 REPLIES 3
Message 2 of 4
Alfred.NESWADBA
in reply to: Anonymous

Hi,

 

using VB.NET you can use AddHandler and RemoveHandler to add/remove eventhandling for a referenced object.

With VBA you have to set the object to nothing for which the eventhandling is active, you might do that during BeginSave event and set it back/reactivate it during the EndSave event.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4

Alfred, I believe the OP refers to AcadDocument's ObjectModified event, which the OP cannot, or may not be easily to set the AcadDocument to nothing to unhook the event handler in VBA..

 

To the OP:

 

If you show your code in the ObjectModified event handler, the things would be much clearer.

 

The event handler has an Object argument, you should make your code to run against only target objects, not all objects whenever ObjectModified event fires.

 

For example, if you only want to process standard blocks (or event blocks with certain name), but not dynamic blocks, you could do this:

 

Private Sub AcadDocument_ObjectModified(ByVal Object As Object)

    Dim blk As AcadBlockReference

    If TypeOf Object is AcadBlockReference Then

        Set blk=Object

        If Not blk.IsDynamicBlock Then

            ''only run your heavy-lifting code now

        End If

    End if

End Sub

 

Or, you can collecting targeting entity Handles/ObjectIds when drawing is opened (or at some stage before the ObjectModified event is triggered) and saving them in module-level public collections/arrays. Then in the event handler, only the Object argument is in the collections/arrays is subject to the heavy-lifting code process.

Norman Yuan

Drive CAD With Code

EESignature

Message 4 of 4

Hi,

 

>> Alfred, I believe the OP refers to AcadDocument's ObjectModified event, which the OP cannot, or may

>> not be easily to set the AcadDocument to nothing to unhook the event handler in VBA..

Yep, using the built-on ACADDOCUMENT/THISDRAWING object is not easy to disable the events.

But you can define your own variable to the THISDRAWING object and so set that also to NOTHING like that

 

Private WithEvents myDOC As AcadDocument

Public Sub EventON()
    Set myDOC = ThisDrawing
End Sub
Public Sub EventOFF()
    Set myDOC = Nothing
End Sub

And yes, with that suggestion every change of the active document has to be forwarded to that EventON sub.

Let's see how OP can work with our information.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost