Get list of loaded external iLogic rules

Get list of loaded external iLogic rules

Anonymous
Not applicable
471 Views
4 Replies
Message 1 of 5

Get list of loaded external iLogic rules

Anonymous
Not applicable

Hi all,

 

Using VBA, how can I get a list of loaded external iLogic rules, as is shown in the iLogic browser?

 

I've had a look through the Autodesk.iLogic.Interfaces.xml file, but I can't see anything there.

 

Any ideas?

0 Likes
472 Views
4 Replies
Replies (4)
Message 2 of 5

mfoster9TD82
Advocate
Advocate
Any progress on this? I'm doing the same with an add-in. The only think I can think of is looking for iLogic files in the directories the external rules are called from.
0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @mfoster9TD82.  Within an iLogic rule, you can type in the following bit of code to access where the external rules are supposed to be stored, if the iLogic Configuration settings have been set-up.  It gives you an Array of String, containing the paths of the directories that are listed there.

Dim oDirs() As String = iLogicVb.Automation.FileOptions.ExternalRuleDirectories

Do access something similar outside of iLogic, I assume you would simply get the ApplicationAddIn object that represents iLogic, then declare a variable as Object, and set its Automation object to that variable.  Then, even though you would be sort of flying blind (no intellisense), I assume there would be a similar iLogicAuto.FileOptions property, that would then have the ExternalRuleDirectories property that you could access, similarly to the line of code above.  Then its just a matter of iterating its files with a search pattern that includes an asterisk (*), followed by the file extension you are using for your external rules.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

WCrihfield
Mentor
Mentor

Here is a simple example code that appears to work for me to get those directories, just to help get you started.

Dim iLogicClassIDString As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
Dim iLogicAddIn As Inventor.ApplicationAddIn = _
ThisApplication.ApplicationAddIns.ItemById(iLogicClassIDString)
Dim oAuto As Object = iLogicAddIn.Automation
Dim oDirs() As String = oAuto.FileOptions.ExternalRuleDirectories
If IsNothing(oDirs) OrElse oDirs.Length = 0 Then
	MsgBox("No directories found.", , "")
Else
	MsgBox(oDirs.Length & " directories found.", , "")
End If

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

WCrihfield
Mentor
Mentor

OK.  Here is an actual VBA macro example which gets these directories, then iterates through them, checking if they are text files, then adds their names to a Collection.  I have my iLogic Configuration settings set up so that my external rules use the ".txt" file extension, so the File.Type check seems to work OK for me, but if you are using a different extension, I am not 100% sure if that filter will work for you.  They are all essentially just text files, but there are 3 different possible file extensions you can choose from.  Then it reports how many if found.  I have included several other MsgBox lines in there at certain points, as data feedback, but left them commented out, because depending on how many directories there are and how many files it finds, that could be a ton of messages you would have to click through.  I'm sure this code could be improved upon, or modified for more specific uses, but this should get you started at least.  I did not continue to show a message for each file's name, because for me that could potentially go into the thousands of pop-up messages.  For now it just reports on quantities.

Sub GetListOfExternalRules()
    Dim iLogicClassIDString As String
    iLogicClassIDString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
    Dim iLogicAddIn As Inventor.ApplicationAddIn
    Set iLogicAddIn = ThisApplication.ApplicationAddIns.ItemById(iLogicClassIDString)
    If Not iLogicAddIn.Activated Then iLogicAddIn.Activate
    Dim oAuto As Object
    Set oAuto = iLogicAddIn.Automation
    Dim oDirs As Variant
    oDirs = oAuto.FileOptions.ExternalRuleDirectories
    If UBound(oDirs) = 0 Then
        Call MsgBox("No directories found.", , "")
        Exit Sub
    End If
    'Call MsgBox(UBound(oDirs) & " directories found.", , "")
    Dim i As Integer
    Dim sDir As String
    Dim FSO As Scripting.FileSystemObject
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim oCol As New Collection
    For i = 0 To UBound(oDirs)
        sDir = oDirs(i)
        'Call MsgBox("sDir = " & sDir, vbInformation, "External iLogic Rule Directory")
        Dim oFolder As Scripting.Folder
        Set oFolder = FSO.GetFolder(sDir)
        If oFolder.Files.Count = 0 Then GoTo NextFolder
        'Call MsgBox("There were " & oFolder.Files.Count & " files within the following folder:" & vbCrLf & oFolder.name, , "")
        Dim oFile As Scripting.File
        For Each oFile In oFolder.Files
            If oFile.Type = "Text Document" Then
                Call oCol.Add(oFile.name)
            End If
        Next oFile
NextFolder:
    Next i
    Call MsgBox("There were " & oCol.Count & " total external iLogic rules found.", vbInformation, "")
End Sub

By the way...just in case you were not aware of this, the iLogic Configuration settings can be found on the Tools tab > Options panel (may have to expand the panel to see it) > iLogic Configuration, which opens a dialog labeled "Advanced iLogic Configuration", similar to the image below.

WCrihfield_0-1669744480600.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes