Hi @madstrolle & @Andrii_Humeniuk. I you choose to use the 'custom' event handler code route, I would suggest using the DocumentEvents.OnSave Event, instead of the ApplicationEvents.OnSaveDocument Event, just to help contain it to that one document, and help eliminate it the handler once the document is closed. I just believe it would be more efficient, and easier to handle. And the DocumentEvents.OnClose Event portion being shown in this example below is most likely not even needed, but I left it in there anyways, for reference. You will notice that I also made a point to set the HandlingCode to NotHandled, to help ensure that the normal event continues to happen after these interruptions, also as reference. Carry on. 👍
Sub Main
If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub
oDDoc = ThisDoc.Document
oDocEvents = oDDoc.DocumentEvents
AddHandler oDocEvents.OnSave, AddressOf oDocEvents_OnSave
AddHandler oDocEvents.OnClose, AddressOf oDocEvents_OnClose
End Sub
Dim oDDoc As DrawingDocument
Dim oDocEvents As DocumentEvents
Sub oDocEvents_OnSave(oTiming As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
If oTiming = EventTimingEnum.kBefore Then
Dim oSheets As Inventor.Sheets = oDDoc.Sheets
Dim oTable As Inventor.CustomTable = Nothing
For Each oSheet As Inventor.Sheet In oSheets
Dim oCTables As Inventor.CustomTables = oSheet.CustomTables
If oCTables.Count = 0 Then Continue For
oTable = oCTables.Item(1)
Exit For
Next
oDDoc.SelectSet.Clear
oDDoc.SelectSet.Select(oTable)
ThisApplication.CommandManager.ControlDefinitions.Item("DrawingTableEditCtxCmd").Execute2(True)
HandlingCode = HandlingCodeEnum.kEventNotHandled
End If
End Sub
Sub oDocEvents_OnClose(oTiming As EventTimingEnum, Context As NameValueMap, ByRef HandlingCode As HandlingCodeEnum)
If oTiming = EventTimingEnum.kBefore Then
RemoveHandler oDocEvents.OnSave, AddressOf oDocEvents_OnSave
HandlingCode = HandlingCodeEnum.kEventNotHandled
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)