iLogic: How to share value between rules?

iLogic: How to share value between rules?

j.pavlicek
Collaborator Collaborator
2,318 Views
5 Replies
Message 1 of 6

iLogic: How to share value between rules?

j.pavlicek
Collaborator
Collaborator

Hello,

is there way how to share value between independent rules (Application scope value?)

 

Why I need it:

  1. I have an IPT used as new part generator. When this IPT is opened, local iLogic rule "ShowForm" is triggered and a form shown
  2. User fill-in the the form and click on a button Save file(s) - local iLogic rule "SaveFiles" is ran.
  3. In "SaveFiles" rule: Copy of the current IPT file is saved as, then oppened* in backgroud and all rules + forms are deleted. IPT is saved and closed.

 

* It has one problem. When the copy is opened in background, iLogic trigger (On Open) is triggered and a new form (in context of the hidden file) is oppened.

 

I'd like to store some "global" variable which is checked in rule "Show form" and prevent form from showing if the document is opened only for iLogic deletion.

 

Thanks for your suggestions.



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Accepted solutions (2)
2,319 Views
5 Replies
Replies (5)
Message 2 of 6

Daan_M
Collaborator
Collaborator

If i understand correctly you already saved your ipt file, you can check the folder if the currentfilename already exists. If it does exist you can exit your sub, something like:

 

Imports System.IO

Sub Main
Dim FilePath as String
Dim FileName as string 'your variable filename

FilePath = "C:/" & FileName

If File.Exists("FilePath") Then
	Exit Sub	
Else 
	'Execute full form code..
End If  
End sub 

 

 

 

0 Likes
Message 3 of 6

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @j.pavlicek 

You can use a sharedvariable.

Ex:

SharedVariable("SomeName") = "Something"

Then retrieve it from another rule in the application like:

Dim Something As String = SharedVariable("SomeName")

(It doesn't have to be a string, just an example)

 

It's also good to know about

If SharedVariable.Exists("SomeName") Then
	...
Message 4 of 6

j.pavlicek
Collaborator
Collaborator

@Daan_M No.

There is Generator.ipt containing:

  • Form1
  • iLogic rule "ShowForm"
  • iLogic rule "SaveFiles"
  • Trigger running "ShowForm" at DocumentOpen

User opens Generator.ipt = rule "ShowForm" is triggered

"ShowForm" opens form "Form1"

User fills-in data in "Form1" and click Save files = "SaveFiles" rule starts

 

"SaveFile" rule:

  1. Saves copy of "Gerator.ipt" as (user input) "Part.ipt" (equivalent of File>Save>Save Copy As...
  2. Because I don't want any iLogic in Part.ipt: Part.ipt is opened in background
  3. All iLogic rules and Forms are deleted in Part.ipt
  4. Part.ipt is saved and closed
  5. End of SaveFile rule

But in step 2 of "SaveFile" is "ShowForm" in "Part.ipt" (which is identical copy of Generator.ipt) triggered. And another Form1 (in context Part.ipt shown). I want to prevent this Form from showing.

 

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 5 of 6

j.pavlicek
Collaborator
Collaborator

@JhoelForshav Nice, thank you. This is what I was looking for.

 

Excuse my curiosity, but what is lifetime of these SharedVariables? Acc. to an article on Autodesk knowledge site it seems to be Application scope variable, so I suppose these variables are destroyed when Inventor is closed. Right?

 



Inventor 2022, Windows 10 Pro
Sorry for bad English.
0 Likes
Message 6 of 6

JhoelForshav
Mentor
Mentor
Accepted solution

They're destroyed when the iLogic addin is terminated. Which basically is when the application is closed. You can also delete them yourself:

SharedVariable.Remove("Something")
'OR
SharedVariable.RemoveAll