Programmatically add new External (iLogic) Rule Directory path within current Inventor session

Programmatically add new External (iLogic) Rule Directory path within current Inventor session

Maxim-CADman77
Advisor Advisor
1,521 Views
8 Replies
Message 1 of 9

Programmatically add new External (iLogic) Rule Directory path within current Inventor session

Maxim-CADman77
Advisor
Advisor

I'd like to modify Advanced iLogic Configuration programmatically within current Inventor session (add one more External Rule Directory path).

 

From this article I believe the Directory list to be modified is a one-size array (of strings).

 

But when I'm trying to resize (enlarge by 1) the array like this (iLogic):

Option Explicit On

Dim ClientId As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}" ' iLogic's GUID
Dim iLogicAddIn As ApplicationAddIn = ThisApplication.ApplicationAddIns.ItemById(ClientId)

Dim iLogicAuto As Object = iLogicAddIn.Automation

Dim path As Object
For Each path In iLogicAuto.FileOptions.ExternalRuleDirectories
	logger.info("Directory name: " & path)
Next

ReDim Preserve iLogicAuto.FileOptions.ExternalRuleDirectories(iLogicAuto.FileOptions.ExternalRuleDirectories.Length) ' ??? Conversion from type 'Object()' to type 'String()' is not valid.

I keep getting error "Conversion from type 'Object()' to type 'String()' is not valid."

 

What I'm missing?

PS:

I kindly hope @MjDeck will find possible to comment on this.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
1,522 Views
8 Replies
Replies (8)
Message 2 of 9

MjDeck
Autodesk
Autodesk
Accepted solution

Yes, it is a one-dimensional array of strings. But you can't modify the elements of that array directly. Instead, you have to assign an array to replace it. So if you want to modify it, first make a copy. Here's a sample rule. 
Note: it would be better to check to see if the array already contains the path being added.

Also, note that in an iLogic rule the Automation object is available on the iLogicVb object. You don't have to get it from the add-in.

Option Explicit On
Dim iLogicAuto = iLogicVb.Automation

' Make a copy to modify
Dim newPaths() As String = iLogicAuto.FileOptions.ExternalRuleDirectories.Clone

Dim path As String
For Each path In newPaths
	Logger.Info("Directory name: " & path)
Next

Dim oldLength = newPaths.Length
ReDim Preserve newPaths(newPaths.Length)
newPaths(oldLength) = "D:\iLogic\Rules" ' add a new path

' Assign the new array back to Inventor:
iLogicAuto.FileOptions.ExternalRuleDirectories = newPaths

Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 3 of 9

Maxim-CADman77
Advisor
Advisor

@MjDeck 

Thank you so much!

One more little consequent question:
What is the right way to have  iLogicVb object declared in context of use Visual Studio for coding?

 

Should I add some Autodesk.iLogic...DLL to my project? And if so which of them?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 9

MjDeck
Autodesk
Autodesk

Hi Maxim - are you developing a standalone EXE, or an Inventor add-in? Or maybe a DLL that is referenced directly in an iLogic rule?
You can't use iLogicVb in a standalone EXE. The other two cases are possible.

To use it in a DLL that is referenced in an iLogic rule, you only need to add a reference to Autodesk.iLogic.Interfaces.dll, and maybe Autodesk.iLogic.Types.dll. The type of iLogicVb is on this page:
https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=4ccb78b0-c35c-4d38-943a-854117da6ced


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 9

Maxim-CADman77
Advisor
Advisor

I'm developing an AddIn (I'm using iLogic code for pre-developing of functions I'm going to add).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 9

MjDeck
Autodesk
Autodesk

In an add-in, you need references to Autodesk.iLogic.Interfaces.dll and Autodesk.iLogic.Types.dll.

You also need a Document object. It's required to create iLogicVb and other standard iLogic objects. If you have a variable named doc declared as a Document, then this will work in VB:

Imports Autodesk.iLogic.Interfaces
' ...
Dim provider = StandardObjectFactory.Create(doc)
Dim iLogicVb = provider.iLogicVb

StandardObjectFactory is described here:
https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=a233a5cb-6f7b-fb33-283f-778245fccc04


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 7 of 9

jdasilvaS39UQ
Advocate
Advocate

Is this possible in VBA? I can get the ilogicaddin but then there are no members in the inspector and it gives an object required error if I try to access anything.

It's strange because I am able to run external rules using ilogicaddin

 

jdasilvaS39UQ_0-1692364410287.png

 

0 Likes
Message 8 of 9

MjDeck
Autodesk
Autodesk

@jdasilvaS39UQ , I'm not sure which topic you're asking about.
You can set the external rule directories from VBA.
But you can't access the StandardObjectFactory or iLogicVb objects from VBA. However, you can do that indirectly. Put the iLogic-specific code in an external rule. Then you can call that external rule from VBA (with arguments if required).


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 9 of 9

jdasilvaS39UQ
Advocate
Advocate

Sorry, I was wondering specifically if you can set external rule directories through VBA. I ended up getting it to work like you said with an external rule and calling that from VBA.

0 Likes