Is it possible to set the VBA (ivb) Project file with an iLogic rule? All users use the same VBA project file located on a network share but now since we have started working from home a few days a week Inventor likes to default this file. So can a rule be made that can simply run and reset it back to the correct location?
Hi @Jason.Rugg. I don't think I have ever tried that, but here is some starter code for your research. I was playing around with controlling VBA stuff from iLogic rules at some point, and have this bit of code you can mess with.
Dim oApp As Inventor.Application = ThisApplication
Dim oVBAProjs As InventorVBAProjects = oApp.VBAProjects
'oVBAProjs.Open("S:\Engineering\VBA\MyVBAProject.ivb")
Dim oMyProj As InventorVBAProject = Nothing
For Each oProj As InventorVBAProject In oVBAProjs
If oProj.Name = "MyVBAProject" And _
oProj.ProjectType = VBAProjectTypeEnum.kUserVBAProject Then
'oProj.ProjectType = VBAProjectTypeEnum.kApplicationVBAProject Then
oMyProj = oProj
Exit For
End If
Next
Dim oComps As InventorVBAComponents = oMyProj.InventorVBAComponents
For Each oComp As InventorVBAComponent In oComps
For Each oMember As InventorVBAMember In oComp.InventorVBAMembers
Dim oArgs As InventorVBAArguments = oMember.Arguments
For Each oArg As InventorVBAArgument In oArgs
If oArg.Name = "ComponentName" And oArg.ArgumentType = "String" Then
oArg.Value = "Part1:1"
End If
Next
Dim oReturned As Object = Nothing
If oMember.MemberType = MemberTypeEnum.kFunctionMember Then
oMember.Execute(oReturned)
End If
'do something with the oReturned value/object
Next
Next
Wesley Crihfield
Wait a second... I do remember this. It is much simpler than all that. There is a simple setting right here:
ThisApplication.FileOptions.DefaultVBAProjectFileFullFilename = "S:\Engineering\VBA\MyVBAProject.ivb"
Wesley Crihfield
That worked great. Now since that sets how our ribbon menu looks with our custom tools the icons don't come back until Inventor is closed and relaunched. Is there a way in the rule that after it sets the correct vba project to have it prompt to close inventor and if you click ok it will auto close close inventor and relaunch?
I know you can prompt the user, asking the question, and I know you can close the Inventor application by code, but I honestly haven't done it from an iLogic rule before. And I do not know of a way to make the Inventor application automatically restart itself from an iLogic rule.
ThisApplication.FileOptions.DefaultVBAProjectFileFullFilename = "S:\Engineering\VBA\MyVBAProject.ivb"
oAns = MsgBox("Just reset the default VBA Project file." & vbCrLf & _
"You will now need to restart the Inventor application so things will be updated." & vbCrLf & _
"Do you want this rule to attempt to close Inventor for you?", vbYesNo + vbQuestion + vbDefaultButton2, "")
If oAns = vbYes Then
ThisApplication.Quit
End If
(My
Wesley Crihfield
@WCrihfield here is the code you posted before, could it be modified to do the same thing for importing the "Customize User Commands" .xml file?
ThisApplication.FileOptions.DefaultVBAProjectFileFullFilename = "S:\Engineering\VBA\MyVBAProject.ivb"
I assume that is the file that you would export (or import) from the Customize dialog box, where you can customize the Ribbon, Keyboard shortcuts, & Marking Menu? No, I do not know of any built-in Inventor API Property where this file location would be stored. The 'default' VBA project setting can be found manually within the File tab of the Application Options dialog, and it had been 'exposed' to the API that we have access to.
The only thing I can think of right now that might help control the customization settings, would be to find the commands for exporting and importing that file, and store the file's location somewhere external, then maybe use the PostPrivateEvents tool to post that files full file name to Inventor's memory, just before executing that import command. I haven't tried it yet myself though, and I am not sure what those commands might be, or if they can be found. There are several commands (as ControlDefinitions) for exporting things, but I did not see any in my list that looked obvious to me that it was for exporting or importing Inventor UI customization.
Wesley Crihfield
@WCrihfield Thanks, yes I figured that might be a long shot but what you described in the second half is essentially what I want to do. We already save the xml file out to a share, was just hoping a similar rule could be made to import that file a bit faster, then I could just run the rule to set new users up with our version of the ribbon or reset it should it get messed up.
Something else does remotely come to mind, but I can't remember which post I found references/examples related to it. I believe it had to do with the desktop shortcut you use to launch your Inventor application. I think you can mess with the 'Target' data, or something like that, to include extra instructions for automatically loading certain things when Inventor first loads. I bet @JelteDeJong would recall something about this, because I believe he got involved in helping someone else out with this idea at the time. I used to have a modified shortcut on my desktop, but have since deleted it.
Wesley Crihfield
I found one of the several posts that touch on that last thing I mentioned in my last post.
Wesley Crihfield
Depending on your Inventor version the information in those post are outdated. Here you find some more information.
Or you could start Inventor like this and you will get a messagebox with the information.
"C:\Program Files\Autodesk\Inventor 2022\Bin\Inventor.exe" /?
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com