Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Possible to set VBA (ivb) Project file with iLogic rule?

12 REPLIES 12
Reply
Message 1 of 13
Jason.Rugg
273 Views, 12 Replies

Possible to set VBA (ivb) Project file with iLogic rule?

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?

12 REPLIES 12
Message 2 of 13
WCrihfield
in reply to: Jason.Rugg

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

EESignature

Message 3 of 13
WCrihfield
in reply to: Jason.Rugg

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

EESignature

Message 4 of 13
Jason.Rugg
in reply to: WCrihfield

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?

Message 5 of 13
WCrihfield
in reply to: Jason.Rugg

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

EESignature

Message 6 of 13
Jason.Rugg
in reply to: WCrihfield

@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"

 

Message 7 of 13
WCrihfield
in reply to: Jason.Rugg

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

EESignature

Message 8 of 13
Jason.Rugg
in reply to: WCrihfield

@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. 

Message 9 of 13
WCrihfield
in reply to: Jason.Rugg

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

EESignature

Message 10 of 13
Jason.Rugg
in reply to: WCrihfield

Interesting, I will wait and see if he replies, thanks for the help.

Message 11 of 13
WCrihfield
in reply to: Jason.Rugg
Message 13 of 13
JelteDeJong
in reply to: WCrihfield

Depending on your Inventor version the information in those post are outdated.  Here you find some more information.

https://knowledge.autodesk.com/support/inventor/troubleshooting/caas/sfdcarticles/sfdcarticles/Inven...

 

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.

EESignature


Blog: hjalte.nl - github.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report