Rule to Set iLogic External Path Directories in VB.net for AddIn

Rule to Set iLogic External Path Directories in VB.net for AddIn

ccoomes
Advocate Advocate
745 Views
3 Replies
Message 1 of 4

Rule to Set iLogic External Path Directories in VB.net for AddIn

ccoomes
Advocate
Advocate

Is it possible to add code in a VB.net add-in to set the iLogic External Rules Directories when a ribbon button is pressed?

 

I have done it by using iLogic Code, but need to add the code to a button in my AddIn so it will create it when once the add-in is installed.  The button is already created in the ribbon I just need the code to add to the button.

0 Likes
746 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Since this is set within the iLogic Configuration dialog, and is accessed by iLogic code with this:

iLogicVb.Automation.FileOptions.ExternalRuleDirectories

it might seem like you can only access these settings by referencing the iLogic add-in, but since you can export these settings from that iLogic Configuration dialog to an XML file, I'm betting there is an XML file either within your Design Data folder or somewhere else in Inventor's install directory that stores these settings.  So if you find that file, and you know how to manipulate it, you may be able to do it that way, without having to reference the iLogic add-in (if it were even possible in another add-in).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

greggeorgi
Contributor
Contributor

This can be achieved by accessing the iLogic automation object from the iLogic addin. (Any addin internals can be manipulated as long as it has exposed itself in it's addin automation section). I personally use it to call external iLogic rules from my addin since its easier to maintain the rules. You can also make use of "iLogicVB.Automation.RulesOnEventsEnabled" or other ilogic features like delayed running mode. Note that this is similar to accessing iLogic from VBA.

 

 

Firstly, the iLogic Addin must be installed on any machine that your addin is used (assuming this is already done...).

 

Add the

Autodesk.iLogic.Automation.dll

to your IDE project references. This DLL should be located in the bin folder of your Inventor install (same folder as Inventor.exe)

 

Then its a matter of accessing the addin. You can grab it via client ID, or loop search it. I prefer loop search, but it is slower.

Imports Inventor
Imports Autodesk.iLogic.Automation
Imports System.Linq    'exposes ienumerable concat function

''' Optional global variable somewhere
Public Shared iLogic As iLogicAutomation

''' In a method somewhere  ("g_inventorApplication" is your application object)

''' Using loop '''

For Each addin As ApplicationAddIn In g_inventorApplication.ApplicationAddIns
    'Debug.Print(addin.ClientId)
    If addin.DisplayName = "iLogic" Then
        iLogic = addin.Automation
        ' you can activate/deactivate the addin and some other functions with the addin object

        ' Add paths to existing
        'Dim ilogicExtDirs As String() = iLogic.FileOptions.ExternalRuleDirectories.Concat({"C:\Folder 1\", "C:\Folder 2\"}).ToArray
        ' Start fresh
        'Dim ilogicExtDirs As String() = {"C:\Folder 1\", "C:\Folder 2\"}
        iLogic.FileOptions.ExternalRuleDirectories = ilogicExtDirs
        Exit For
    End If
Next

'''' Get addin via client ID '''

iLogic = g_inventorApplication.ApplicationAddIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}").Automation

' Add paths to existing
'Dim ilogicExtDirs As String() = iLogic.FileOptions.ExternalRuleDirectories.Concat({"C:\Folder 1\", "C:\Folder 2\"}).ToArray
' Start fresh
'Dim ilogicExtDirs As String() = {"C:\Folder 1\", "C:\Folder 2\"}
iLogic.FileOptions.ExternalRuleDirectories = ilogicExtDirs

 

The only caveat i can think of is that the iLogic addin is potentially not enabled/loaded when your addin is loaded, this can be checked by looking at the addin.Activated property, or in my case, I don't fully load my addin until inventor fires it's onReady event (defeats the purpose of onReady, but oh well). Since you want to run this via a ribbon button, you might not have any issue since ribbon buttons cannot be clicked until onReady is fired anyways.

 

Hope this helps!

Message 4 of 4

n_krisch
Enthusiast
Enthusiast

Thank you so much for this solution! ‌‌
Works great!


Two Notes:
I had to add Autodesk.iLogic.Interfaces.dll in addition to the Autodesk.iLogic.Automation.dll from the same directory.
And I needed to to change target .Net Framwork from 4.5 to at least 4.7 to be able to use the two dll.

Maybe this will help someone with similar problems.

0 Likes