Preventing ObjectModified event from firing when saving/regening
I implemented some event handlers to manipulate some objects when some specific MTexts are manually modified with the "MTEDIT" command. Everything works fine except that the "QSAVE" and "REGEN" commands take a bit longer to execute than with the events disabled (about 1-2 seconds more in a drawing with not that many objects). This must be happening because the ObjectModified event is firing countless times when saving. I even put an if statement for the "QSAVE" command inside the event, but it still slows down the saving.
Here is what I first tried:
Public mtextObjHandle As String, currentCommand As String Sub AcadDocument_BeginCommand(ByVal CommandName As String) currentCommand = CommandName End Sub Sub AcadDocument_ObjectModified(ByVal Object As Object) If currentCommand <> "QSAVE" And currentCommand <> "VBAIDE" And currentCommand <> "REGEN" Then If Object.ObjectName = "AcDbMText" Then mtextObjHandle = Object.handle End If End If End Sub Sub AcadDocument_EndCommand(ByVal CommandName As String) If CommandName = "MTEDIT" Then Dim mtextObj As AcadMText Set mtextObj = ThisDrawing.HandleToObject(mtextObjHandle) 'here goes the rest of the code End If End Sub
I searched some solutions but didn't manage to prevent the event from firing. This next solution resembles something that might work for the "QSAVE" command (probably not for the "REGEN" command), but the event is still firing when saving.
Public mtextObjHandle As String, currentCommand As String Public WithEvents myDOC As AcadDocument Public Sub EventON() Set myDOC = ThisDrawing End Sub
Public Sub EventOFF() Set myDOC = Nothing End Sub Sub AcadDocument_BeginSave(ByVal FileName As String) EventOFF End Sub Sub AcadDocument_EndSave(ByVal FileName As String) EventON End Sub Sub myDOC_BeginSave(ByVal FileName As String) EventOFF End Sub Sub myDOC_EndSave(ByVal FileName As String) EventON End Sub Sub myDOC_ObjectModified(ByVal Object As Object) (...) End Sub Sub myDOC_EndCommand(ByVal CommandName As String) (...) End Sub
I am probably doing something wrong, but I never worked with events before so I don't know what might be.
Thank you in advance.