Hi @mattias-bergson. Those two text files were just exploratory type codes to get you familiar with where to find the things you will need to find. Here is an example code more like what you asked for in your second response. It tries to open an IDW type drawing file. Then tries to open an IVB file for the VBA project. Then it tries to find your two macros and run them. You will need to know the names of the Modules that you put them into, and the name of the main Sub or Function within that Module, in order to be able to run them. And since I wasn't sure whether your macros were Subs or Functions, I left more code in there than may be necessary. You will need to edit the drawing file's path & name, the VBA project file's path & name, the module names, and maybe even the macro names in order to make this work for you.
'iLogic rule way to run a macro:
'oResult = iLogicVb.RunMacro(sProjectName, sModuleName, sMethodName, {oInputArg1, oInputArg2})
'Inventor API way to run a VBA macro:
'open an IDW drawing file:
Dim sDrawingFile As String = "C:\Temp\MyDrawing.idw"
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Open(sDrawingFile, True) 'True = Visible
'open the VBA project, then find the object it represents
Dim sVBAProjectFile As String = "C:\Temp\MyVBAProject.ivb"
Dim oVBAProjects As InventorVBAProjects = ThisApplication.VBAProjects
oVBAProjects.Open(sVBAProjectFile)
Dim oMyProj As InventorVBAProject = Nothing
For Each oProj As InventorVBAProject In oVBAProjects
If oProj.Name = "MyVBAProject" Then
oMyProj = oProj
Exit For
End If
Next
'find the first Module, then the Sub or Function routine within it, by name (the macro)
Dim oModule1 As InventorVBAComponent = oMyProj.InventorVBAComponents.Item("Module1")
Dim oRoutine1 As InventorVBAMember = oModule1.InventorVBAMembers.Item("macro1")
Dim oFunctionReturnValue1 As Object = Nothing
If oRoutine1.MemberType = MemberTypeEnum.kFunctionMember Then
oRoutine1.Execute(oFunctionReturnValue1)
Else
oRoutine1.Execute 'run the macro
End If
Dim oModule2 As InventorVBAComponent = oMyProj.InventorVBAComponents.Item("Module2")
Dim oRoutine2 As InventorVBAMember = oModule2.InventorVBAMembers.Item("macro2")
Dim oFunctionReturnValue2 As Object = Nothing
If oRoutine2.MemberType = MemberTypeEnum.kFunctionMember Then
oRoutine2.Execute(oFunctionReturnValue2)
Else
oRoutine2.Execute
End If
'update, save, and close the drawing
oDDoc.Update2(True) 'True = accept errors & continue
'oDDoc.Save2(True) 'True = save dependents
'oDDoc.Close(True) 'True = skip save
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)