Run Macro On Save

Run Macro On Save

isocam
Collaborator Collaborator
924 Views
3 Replies
Message 1 of 4

Run Macro On Save

isocam
Collaborator
Collaborator

The attached addin works Ok except that it only accepts "ipt" files.

 

Can anybody upgrade the addin and compile it so that it can accept "ipt", "iam" & "idw" files?

 

Many thanks in advance!!!

 

 

0 Likes
925 Views
3 Replies
Replies (3)
Message 2 of 4

MegaJerk
Collaborator
Collaborator

For the people that do not have Visual Studios, perhaps you could explain what it is you're doing On Save. Perhaps it could be done via iLogic / API instead / Event Triggers instead? 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
0 Likes
Message 3 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

Open the StandardAddInServer.vb with an Texteditor, scroll down to the end and replace the OnSave-Sub with this:

 

Private Sub m_applicationEvents_OnSaveDocument(ByVal DocumentObject As Inventor._Document, ByVal BeforeOrAfter As Inventor.EventTimingEnum, ByVal Context As Inventor.NameValueMap, ByRef HandlingCode As Inventor.HandlingCodeEnum) Handles m_applicationEvents.OnSaveDocument

            If BeforeOrAfter = EventTimingEnum.kBefore Then
                'Lets make sure that the active document is a part document
                If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                    Try
                        Dim invVBAProject As InventorVBAProject = m_inventorApplication.VBAProjects.Item(1)
                        Dim invModule As InventorVBAComponent = invVBAProject.InventorVBAComponents.Item("Module01")
                        Dim invSub As InventorVBAMember = invModule.InventorVBAMembers.Item("Main")
                        invSub.Execute()
                    Catch ex As Exception

                    End Try

                End If

                If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                    Try
                        Dim invVBAProject As InventorVBAProject = m_inventorApplication.VBAProjects.Item(1)
                        Dim invModule As InventorVBAComponent = invVBAProject.InventorVBAComponents.Item("Module01")
                        Dim invSub As InventorVBAMember = invModule.InventorVBAMembers.Item("Main")
                        invSub.Execute()
                    Catch ex As Exception

                    End Try

                End If

                If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
                    Try
                        Dim invVBAProject As InventorVBAProject = m_inventorApplication.VBAProjects.Item(1)
                        Dim invModule As InventorVBAComponent = invVBAProject.InventorVBAComponents.Item("Module01")
                        Dim invSub As InventorVBAMember = invModule.InventorVBAMembers.Item("Main")
                        invSub.Execute()
                    Catch ex As Exception

                    End Try

                End If


            End If

        End Sub

 

 EDIT: compiled dll attached (replace txt with dll)

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 4 of 4

xiaodong_liang
Autodesk Support
Autodesk Support

I think krieg's code answers this question. If the code in each branch is same, I would suggest to combine all conditions, e.g.

 

DocumentTypeEnum docType = m_inventorApplication.ActiveDocument.DocumentType

 

If docType = DocumentTypeEnum.kPartDocumentObject Or
    docType = DocumentTypeEnum.kAssemblyDocumentObject Or
    docType = DocumentTypeEnum.kDrawingDocumentObject Then

   

     .....

End If

 

0 Likes