After ignoring the problem for months I finally came up with a solution:
When inventor launches, the location of the external rules directory is loaded. Where is that information stored? It’s not located in C:\Users\*username*\AppData\Local\Autodesk\Inventor 2016\iLogicPreferences. I know this because inventor doesn’t read that file every time it starts up. It’s also not stored in the application options configuration. That must mean that it is a configuration file located somewhere else since it is very unlikely that the location is stored in the windows registry.
Running off of that assumption I found a file named “iLogicOptions.xml” in C:\Users\*user*\AppData\Roaming\Autodesk\Inventor 2016\iLogicPreferences. In this file is the setting that locates the external rules directory that Inventor reads when it opens. That file is appended each time you close inventor or update the options. And it is re-read each time you open the iLogic Configuration box.
I now have a solution:
- Have inventor create/edit the .xml file
- Launch the ilogic Configuration menu
- Tell windows to press Enter
SyntaxEditor Code Snippet
myname = ThisApplication.GeneralOptions.UserName
'MsgBox(myname)
iLogicPath = "C:\Users\" & myname & "\AppData\Roaming\Autodesk\Inventor 2016\iLogicPreferences\"
'____Create and write to a text file_________________
oWrite = System.IO.File.CreateText(iLogicPath & "iLogicOptions.xml")
oWrite.WriteLine("<?xml version=""1.0"" encoding=""utf-8""?>")
oWrite.WriteLine("<ShareableOptions xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">")
oWrite.WriteLine(" <ExternalRuleDirectories>")
oWrite.WriteLine(" <string>Path1</string>")
oWrite.WriteLine(" <string>Path2</string>")
oWrite.WriteLine(" </ExternalRuleDirectories>")
oWrite.WriteLine(" <ExternalRuleFilenames />")
oWrite.WriteLine(" <ExternalRuleDefaultExtension>.iLogicVb</ExternalRuleDefaultExtension>")
oWrite.WriteLine("</ShareableOptions>")
oWrite.Close()
'System.Threading.Thread.CurrentThread.Sleep(3000) 'Just in case the server is running slow and trying to catch up
Dim oControlDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.Configuration")
oControlDef.Execute2(False)
InventorVb.RunMacro("DocumentProject", "Module1", "PressEnter")
Here's the VBA Macro. I use the AppActivate command just in case the user changes the focus from Inventor to another program because the SendKeys command executes in whatever application is activated. And the default focus button in the iLogic Configuration menu is "OK".
Sub PressEnter()
AppActivate "Autodesk Inventor 2016"
SendKeys "{Enter}"
End Sub