Hi,
We use a normal table for our revisions.
The problem is that people often forget to update the table.
Is there a way to open the table automatically, e.g trigger it to open before save?
Thanks in advance😊
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by WCrihfield. Go to Solution.
Hi @madstrolle . Add this code to the trigger "After Save Document".
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDDoc As DrawingDocument = oInvApp.ActiveDocument
Dim oControl As ControlDefinitions = oInvApp.CommandManager.ControlDefinitions
Dim oCtrlDef As ControlDefinition
Dim oTables As RevisionTables = oDDoc.ActiveSheet.RevisionTables
If oTables.Count = 0 Then Exit Sub
oDDoc.SelectSet.Select(oTables(1))
oCtrlDef = oControl("DrawingRevisionTableEditCtxCmd")
oCtrlDef.Execute()
oDDoc.Save()
Or this a rule, but this needs to be added to the "After Open Document" trigger.
Class ThisRule
Private oInvApp As Inventor.Application
Private WithEvents oApplicationEvents As ApplicationEvents
Sub main
If SharedVariable.Exists("ApplicationEvent") Then Exit Sub
oInvApp = ThisApplication
oApplicationEvents = oInvApp.ApplicationEvents
sharedVariable("ApplicationEvent") = oApplicationEvents
End Sub
Private Sub oAPP_onsave(DocumentObject As Document,
BeforeOrAfter As EventTimingEnum,
Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) _
Handles oApplicationEvents.OnSaveDocument
If BeforeOrAfter = EventTimingEnum.kBefore Then
Dim oDDoc As DrawingDocument = oInvApp.ActiveDocument
Dim oControl As ControlDefinitions = oInvApp.CommandManager.ControlDefinitions
Dim oCtrlDef As ControlDefinition
Dim oTables As RevisionTables = oDDoc.ActiveSheet.RevisionTables
If oTables.Count = 0 Then Exit Sub
oDDoc.SelectSet.Select(oTables(1))
oCtrlDef = oControl("DrawingRevisionTableEditCtxCmd")
oCtrlDef.Execute()
End If
End Sub
End Class
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi @Andrii_Humeniuk ,
Thank you for your quick responce.
Unfortunately it's not working. Is it because you have made it for "revision table"?
This is just a normal table, as in the picture.
Try using either "DrawingTableCmd" or "DrawingTableEditCtxCmd", instead.
Wesley Crihfield
(Not an Autodesk Employee)
Code 1:
Dim oInvApp As Inventor.Application = ThisApplication
Dim oDDoc As DrawingDocument = oInvApp.ActiveDocument
Dim oControl As ControlDefinitions = oInvApp.CommandManager.ControlDefinitions
Dim oCtrlDef As ControlDefinition
Dim oTables As CustomTables = oDDoc.ActiveSheet.CustomTables
If oTables.Count = 0 Then Exit Sub
oDDoc.SelectSet.Select(oTables(1))
oCtrlDef = oControl("DrawingTableEditCtxCmd")
oCtrlDef.Execute()
oDDoc.Save()
Code 2:
Class ThisRule
Private oInvApp As Inventor.Application
Private WithEvents oApplicationEvents As ApplicationEvents
Sub main
If SharedVariable.Exists("ApplicationEvent") Then Exit Sub
oInvApp = ThisApplication
oApplicationEvents = oInvApp.ApplicationEvents
sharedVariable("ApplicationEvent") = oApplicationEvents
End Sub
Private Sub oAPP_onsave(DocumentObject As Document,
BeforeOrAfter As EventTimingEnum,
Context As NameValueMap,
ByRef HandlingCode As HandlingCodeEnum) _
Handles oApplicationEvents.OnSaveDocument
If BeforeOrAfter = EventTimingEnum.kBefore Then
Dim oDDoc As DrawingDocument = oInvApp.ActiveDocument
Dim oControl As ControlDefinitions = oInvApp.CommandManager.ControlDefinitions
Dim oCtrlDef As ControlDefinition
Dim oTables As CustomTables = oDDoc.ActiveSheet.CustomTables
If oTables.Count = 0 Then Exit Sub
oDDoc.SelectSet.Select(oTables(1))
oCtrlDef = oControl("DrawingTableEditCtxCmd")
oCtrlDef.Execute()
End If
End Sub
End Class
The conditions for triggers are the same as in the previous comment.
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
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)
Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor
LinkedIn | My free Inventor Addin | My Repositories
Did you find this reply helpful ? If so please use the Accept as Solution/Like.
Hi @WCrihfield ,
I know I said it was working perfectly.
But there is one thing that I have noticed now.
If I open an IDW and change something, save it and close it again, it works fine.
But if I change something and save it and make another change and save it again, it opens the table 2 times.
It becomes a bit annoying if you have made changes 10 times, you have to close the table 10 times.
It occurs only when you have the same IDW open. So if I close it and open it again it starts from the beginning.
Hope it makes sense😊
Hi @madstrolle. We could make this a 'one shot' routine, instead of a repeating routine, if that would work better for you. What I mean is, at the end of the code for responding to the OnSave event, we can include the 'RemoveHandler' line of code that you see within the OnClose routine. That will cause it to only respond that first time, then the event handler will be gone, so it will not respond anymore.
Just copy this line:
RemoveHandler oDocEvents.OnSave, AddressOf oDocEvents_OnSave
and put it just before the 'End If' line near the end of the 'oDocEvents_OnSave' Sub routine. You can likely get rid of the oDocEvents_OnClose Sub routine too, because since these events are based on that specific document, they will be destroyed when the document is finally closed anyways. I have a couple of my event handler codes set-up as 'one shot' reactions also, so it is not that uncommon.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.