How to store "iLogic settings"?

How to store "iLogic settings"?

j.pavlicek
Collaborator Collaborator
350 Views
4 Replies
Message 1 of 5

How to store "iLogic settings"?

j.pavlicek
Collaborator
Collaborator

Hello, I have a lot of external rules where some strings are hard-coded. For example: Style names. When style name is changed change in every rule using it is needed.

 

What is suggested approach to store this data in one place? I would like to have single also human-readable file put in the external rules folder.

 

YAML seems great, but I'm afraid there is no built-in YAML parse functionality in iLogic (VB.NET).

 

What have I use?



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
351 Views
4 Replies
Replies (4)
Message 2 of 5

Michael.Navara
Advisor
Advisor

One of the possible approaches is to use SharedVariable. You can store any object in them. For example instance of class with your settings. Then you can create one rule for setup and many other rules which can use the settings.

This rules should be external.

 

There is one disadvantage. You are not able to use IntelliSense for settings. 

 

InitSettings.iLogicVb

Sub main
	Dim settingsVariableName = "MySettings"

	If SharedVariable.Exists(settingsVariableName) Then Return

	SharedVariable(settingsVariableName) = New MySettings
End Sub


Class MySettings
	Public Text As String = "My string setting"
	Public Number As Double = 20

End Class

 

UseSettings.iLogicVb

'Initialize settings
iLogicVb.RunExternalRule("InitSettings")

'Get settings instance
Dim mySettings = SharedVariable("MySettings")

'Use settings values
Logger.Info(mySettings.Text)
Logger.Info(mySettings.Number)

 

 

 

 

 

0 Likes
Message 3 of 5

WCrihfield
Mentor
Mentor

Hi @j.pavlicek.  If you want these settings stored within your external rules directory, you could simply write the data to a text file in that directory, then retrieve the data from that text file as needed by your other rules.  But one other perhaps more intuitive way might be to simply store them in another external iLogic rule, since they are basically just text files too.  Then you could use the 'AddVbFile' tool to reference the other external iLogic rule from any other rule.  There are some preparations that would need to be taken in order to set that up, but it can be a pretty nice tool.  You can read more about it here:  Advanced iLogic Techniques Reference

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 5

Michael.Navara
Advisor
Advisor

Nice @WCrihfield  

In this case it is much easier then my first approach. And intelliSense is also available.

In this case is not possible to change settings from code, but may be this is not required.

 

Settings.vb

 

 

 

Public Class MySettings

	Public Shared Text As String = "My string"
	Public Shared Number As Double = 10
	
End Class

'AND/OR

Public Module MySettings2

	Public Text As String = "My string 2"
	Public Number As Double = 20

End Module

 

 

 

UseSettings.iLogic.vb

 

 

AddVbFile "C:\Full\Path\To\Settings.vb"

Logger.Debug(MySettings.Text)
Logger.Debug(MySettings.Number)

Logger.Debug(MySettings2.Text)
Logger.Debug(MySettings2.Number)

 

 

 

 

Message 5 of 5

WCrihfield
Mentor
Mentor

You can also use the same 'Class' name as the default one implied/used in regular iLogic rules, 'ThisRule'.  That makes the stuff in the other external rule like an extension of the same main class being used in your current rule.  I have not tried changing a value of a referenced variable this way though, and checking to see if it changed anything in the source, because I usually just use these referenced external rules for Subs, Functions, Enums, and such.  Of course you could always just edit the text file by code though, when its not currently being referenced, and therefore likely in a ReadOnly type mode.  I have definitely changed the content of one rule from another before on several occasions.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)