iLogic: Running an External Rule In A Sub-Folder With A NameValueMap

iLogic: Running an External Rule In A Sub-Folder With A NameValueMap

Nathan_Gallant
Contributor Contributor
3,813 Views
12 Replies
Message 1 of 13

iLogic: Running an External Rule In A Sub-Folder With A NameValueMap

Nathan_Gallant
Contributor
Contributor

Hello,

 

I've come across some strange behavior in iLogic that I need a work-around for.

 

I have a vaulted External Rules folder which contains several iLogic rules, along with sub-folders containing several more rules. Only the top level External Rules folder is added in the iLogic Configuration Directories menu.

 

The below function will run an external rule no matter where it is in the external rules directory (even if it's in a sub-folder). This behaves as I would expect.

iLogicVb.RunExternalRule("ruleFileName")

 

If I want to run the exact same function with a NameValueMap, the external rule MUST be directly under the top level external rules directory. If it is saved in a sub-folder the function cannot find the rule. WHY?

Dim map As Inventor.NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
map.Add("Arg1", "Arg1Value")
iLogicVb.RunExternalRule("ruleFileName", map)

 

The only alternative I see is to add all the sub-folders to the iLogic Configuration Directories Menu as well. This will not work for us because we have 30+ users that would be required to map all these folders exactly the same way. Most of our users have zero Inventor knowledge and are simply using a highly automated version (hence the iLogic).

 

Any help in finding an alternative would be greatly appreciated!

Thanks!

0 Likes
Accepted solutions (2)
3,814 Views
12 Replies
Replies (12)
Message 2 of 13

WCrihfield
Mentor
Mentor

We have a fairly similar situation, but don't have any problems.

Basically, I set up all the sub-folders within the 'Advanced iLogic Configuration' dialog box, then use the Export button at the bottom to Export the XML settings document.  Then I email all other users (reusable email template), and either attach this file, or a link to this file on the network, with instructions to go to this dialog box, and use the Import button to import this file.  Quick & easy.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 13

Nathan_Gallant
Contributor
Contributor

Thanks for the reply @WCrihfield.

I was kind of hoping this could be my last resort solution.

We are incredibly fast paced, and with so many inexperienced users I would prefer not to rely on them continually updating their configuration settings whenever our development team makes changes.

 

It would be nice to have a method of directing the iLogic to look in a specific location when calling external rules. Similar to the functionality available for adding a resource into your code.

AddResources "fileName.resources" 

 

0 Likes
Message 4 of 13

WCrihfield
Mentor
Mentor

I've got something else you can use then.

'Get or Set the array of strings that represent the directories in which iLogic should search for external rules.
Dim oXDirs() As String = iLogicVb.Automation.FileOptions.ExternalRuleDirectories

You can use this in its own external iLogic rule as a Public Sub, then 'inject' it into the top (header) of your other rules with AddVbFile "External Rule Full Path & File Name"

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 13

WCrihfield
Mentor
Mentor

Something similar to this:

'Lets assume we have 8 directories we want it to search for external iLogic rules within
Dim oXDirs(7) As String 'because 0 is counted as first item
'Either specify them manually here, or attempt to extract them from
'the XML document created by the Export option within the dialog.
oXDirs(0) = "S:\Engineering\CAD\External iLogic\Dir1\"
oXDirs(1) = "S:\Engineering\CAD\External iLogic\Dir2\"
oXDirs(2) = "S:\Engineering\CAD\External iLogic\Dir3\"
oXDirs(3) = "S:\Engineering\CAD\External iLogic\Dir4\"
oXDirs(4) = "S:\Engineering\CAD\External iLogic\Dir5\"
oXDirs(5) = "S:\Engineering\CAD\External iLogic\Dir6\"
oXDirs(6) = "S:\Engineering\CAD\External iLogic\Dir7\"
oXDirs(7) = "S:\Engineering\CAD\External iLogic\Dir8\"
iLogicVb.Automation.FileOptions.ExternalRuleDirectories = oXDirs

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 13

Nathan_Gallant
Contributor
Contributor
Accepted solution

Thanks for the suggestion @WCrihfield.

This solution works. I actually ended up exploring a bit with the idea of mapping all sub-folders and came up with this.

Sub Main()
	Call AddExternalDirsToInventor
End Sub

Private Sub AddExternalDirsToInventor()
	Dim externalRulesDir As String = "C:\_Vault\CAD Stds\Inventor\iLogic\External Rules"
	Dim subdirs As IEnumerable(Of String) = System.IO.Directory.EnumerateDirectories(externalRulesDir, "*", System.IO.SearchOption.AllDirectories)
	subdirs = subdirs.Prepend(externalRulesDir)
	Dim oXDirs() As String = subdirs.ToArray()
	        
	iLogicVb.Automation.FileOptions.ExternalRuleDirectories = oXDirs
End Sub

This function will add all of the sub-folders inside our external rules directory anytime it's run.

I placed this rule directly inside our 4 most common templates with a trigger to run after document open.

I also turned it into an external rule, therefore any rules we write inside templates that call an external rule can call this rule first to ensure all external rules sub-folders are up to date.

Message 7 of 13

Ced495
Enthusiast
Enthusiast
This worked very well. Thanks!
Only thing I had was that it also tried to map Vault hidden folders "...\_V" that generate in all the sub folders. So I got errors for each of those folders, like this: "The following external rule directory either does not exist or is hidden: C:\[Vault]\4. Design Data\iLogic\Macro\_V" and click [OK].
Perhaps there can be an exclusion for folder "_V" or to not look in hidden folders? It didn't help if I disabled "Hidden items" in file explorer.
0 Likes
Message 8 of 13

WCrihfield
Mentor
Mentor

Hi @Ced495.  Would changing 'System.IO.SearchOption.AllDirectories' to 'System.IO.SearchOption.TopDirectoryOnly' work in your situation (EnumerateDirectories method).  Setting it that way will cause it to not look down within any sub directories.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 13

Ced495
Enthusiast
Enthusiast
That wouldn't work for me. I had an issue that rules saved to sub directories stopped working after inventor restart. I run rules by making toolbar shortcuts with VBA, and after a restart, the shortcuts give an error that they can't find the rule if it was in a sub folder. The solution of this thread fixes that by mapping all of the sub directories as well and I could add a button to execute the rule if needed. Like the solution mentioned, I could also add this "mapping rule" to run automatically on file open but currently it gives like 7 errors for each of the different "_V" hidden folders - so having that spam on every document open would not be good. In this case I really need to exclude hidden folders if possible, or to exclude folder if it has "_" or "_V" in it, then I could run the rule every document open. That would mean any new rule folders would get mapped automatically and other benefits.
0 Likes
Message 10 of 13

WCrihfield
Mentor
Mentor

Hi @Ced495.  I just did a little additional research into this EnumerateDirectories method mentioned above, and I now believe there may still be a way to make it work the way you want it to.  There are 4 versions of that method, each with slightly different input requirements.  The one variation that is asking for 'EnumerationOptions' as its last input seems to be the one you would need to use in this situation.  Within the EnumerationOptions are several additional properties for customizing how the enumeration will work.  One of its properties is IgnoreInaccessible.  Another of its properties is called AttributesToSkip, which represents a FileAttributes (an Enum).  One of the Enum fields within that is the 'Hidden' status.  I'm guessing you could use those additional settings within your code to further customize it to your specific needs.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 11 of 13

Ced495
Enthusiast
Enthusiast

Thanks for the help @WCrihfield, I am far from a pro so I tried my best to understand the links you referred and I got errors. I tried some variations I could think of, but no good.

My best attempt:

Sub Main()
	Call AddExternalDirsToInventor
End Sub

Private Sub AddExternalDirsToInventor()
	Dim externalRulesDir As String = "C:\[Vault]\4. Design Data\iLogic\Macro\"
	'Dim subdirs As IEnumerable(Of String) = System.IO.Directory.EnumerateDirectories(externalRulesDir, "*", System.IO.SearchOption.AllDirectories)
	Dim subdirs As IEnumerable(Of String) = System.Collections.Generic.IEnumerable.EnumerateDirectories(externalRulesDir, "*", System.IO.EnumerationOptions.IgnoreInaccessible)
	subdirs = subdirs.Prepend(externalRulesDir)
	Dim oXDirs() As String = subdirs.ToArray()
	        
	iLogicVb.Automation.FileOptions.ExternalRuleDirectories = oXDirs
End Sub

Errors:

Error on Line 8 : 'IEnumerable' is not a member of 'Generic'.
Error on Line 8 : 'EnumerationOptions' is not a member of 'IO'.

It doesn't seem to me I can take the structure from learn.microsoft .com and use it in inventor. Seems like there needs to be some adjustments for it to function. Any suggestions? Thanks.

0 Likes
Message 12 of 13

Nathan_Gallant
Contributor
Contributor
Accepted solution

Hello @Ced495,

 

A bunch of my colleagues ran into this same issue a couple years ago. I recall it had something to do with an Inventor or Vault update, but not exactly which update. We are not on the latest releases but have definitely updated since then without issue (currently Vault 2022.0 and Inventor Professional 2022.4.1).

 

However, I did create a rule that seemed to do the trick during the time we were having issues. We still have people running this every so often when they have issues with iLogic. It just resets your iLogic Configuration menu and remaps your directories again.

 

Option Explicit On
Class
The_Funkery Sub Main() Dim externalRulesDir As String = "C:\_Vault\CAD Stds\Inventor\iLogic\External Rules" Dim subdirs As IEnumerable(Of String) = System.IO.Directory.EnumerateDirectories(externalRulesDir, "*", System.IO.SearchOption.AllDirectories) subdirs = subdirs.Prepend(externalRulesDir) Dim oXDirs As List(Of String) = subdirs.ToList() For Each oXDir As Object In subdirs.ToArray() Dim obj As New System.IO.DirectoryInfo(oXDir) If (obj.Attributes And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then oXDirs.Remove(oXDir) End If Next iLogicVb.Automation.FileOptions.ExternalRuleDirectories = oXDirs.ToArray() End Sub End Class
 
 
Also, here is an updated version of the original rule that will also map your Add-in directory.
 
Class iLogicConfiguration

	Sub Main()
		Call AddExternalDirsToInventor
		Call SetAddinPath
	End Sub


	Sub AddExternalDirsToInventor()
		Dim externalRulesDir As String = "C:\_Vault\CAD Stds\Inventor\iLogic\External Rules"
		Dim subdirs As IEnumerable(Of String) = System.IO.Directory.EnumerateDirectories(externalRulesDir, "*", System.IO.SearchOption.AllDirectories)
		subdirs = subdirs.Prepend(externalRulesDir)
		Dim oXDirs() As String = subdirs.ToArray()
		        
		iLogicVb.Automation.FileOptions.ExternalRuleDirectories = oXDirs
	End Sub

	Sub SetAddinPath()
		Dim iLogicAddinDir As String = "C:\_Vault\CAD Stds\Inventor\iLogic\iLogic Addins"
		iLogicVB.Automation.FileOptions.AddinDirectory = iLogicAddinDir
	End Sub

End Class

 

0 Likes
Message 13 of 13

Ced495
Enthusiast
Enthusiast
Thanks! I will try it out once I get a chance.
0 Likes