iLogic Progress Bar when rules run

iLogic Progress Bar when rules run

ahmed.hagi
Enthusiast Enthusiast
1,278 Views
6 Replies
Message 1 of 7

iLogic Progress Bar when rules run

ahmed.hagi
Enthusiast
Enthusiast

Is it possible to create a progress bar that increments when ilogic rules have been run?

 

I can only seem to find examples that count assembly components or whether a file has been exported or not. 

0 Likes
1,279 Views
6 Replies
Replies (6)
Message 2 of 7

Eide.N
Advocate
Advocate

A progress bar has to indicate some type of progress, usually like 1, 2, 3 (etc.) of 30 things that the script is doing. It could be time as well, but you need to indicate something that is progressing. What would you be indicating the progress of?

0 Likes
Message 3 of 7

ahmed.hagi
Enthusiast
Enthusiast

I have a configurator that runs something in the region of 64 rules, and it takes a while to run. I just wanted a progress bar to indicate the progress of each of these rules running. Maybe to progress the status as each rule has run?

0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

   Although this may be doable, I believe it would be very complicated to set-up.  I believe you would have to use something like SharedVariables or RuleArguments within each rule that will provide some sort of feedback to the rule running the ProgressBar, so that it knows when to update.  Then the rule with the ProgressBar would likely have to incorporate some sort of 'wait...check...wait...check again' loop to keep up with the feedback.  When dealing with Windows Forms, you have a certain set of Controls and those controls have 'Events' you can create 'Event Handlers' for, but iLogic rules are different.

   Here are a couple of links to these item's help pages, but there is likely much more info available about them and how to use them here on the forums.  Basically they provide a means by which to communicate (or share) data between different iLogic rules.

ISharedVariable Interface 

IRuleArguments Interface 

 

   Also, here's a very simple example of a ProgressBar set-up that simply uses a Sleep sub as its 'what to do' loop, you may or may not find useful.

Dim oStep As Integer
Dim oSteps As Integer = 10 ' <<< CHANGE THIS >>>
Dim oProgressBar As Inventor.ProgressBar = ThisApplication.CreateProgressBar(False, oSteps, "SAMPLE TITLE", True)
'Here you can choose to specify a starting message
oProgressBar.Message = "Starting a process..."
For oStep = 1 To oSteps
	'do something
	'You can also update the Message shown within ght Progress Bar with each loop.
	oProgressBar.Message = "Processing Step " & oStep & " Of " & oSteps
	System.Threading.Thread.Sleep(New TimeSpan(0,0,1))
	'Then each time you loop through some process use the following line to update the Progress Bar
	oProgressBar.UpdateProgress
Next
oProgressBar.Message = "Processing Finished"
'Then after the loop is done, you can close the Progress Bar like this
oProgressBar.Close

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

ahmed.hagi
Enthusiast
Enthusiast

Wow, that is much more complicated than I imagined. I thought there might be a simple way to just create a loop and increase the value of a global variable from each rule as it runs and then update the progress bar based on this, but nothing is that simple i gues 😞

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

   The ProgressBar may not be a good fit for this situation, but I've attempted to create something you can try, if you want.  I'm not sure if this will work for your situation or not, but I put some code together that will attempt to keep up with your rules running in the background.  Keep in mind that some rules may finish running in just milliseconds, while other may take minutes, so it may not look that great, if it functions at all.  When you use the UpdateProgress sub, it only increments the progress bar by one each time, but each time the loop code checks the value of the shared variable, there may have been several rules that have ran, so I'm not sure how it would handle that situation.  I've set the initial value for the total number of steps the ProgressBar will take to 64.  You can change this if you want, but you have to set this value when you create a progress bar.  When it reaches that number it thinks it is done. 

   So, in order for this to have a chance of working, you would need to edit each rule that will be running, to add some code to them all.  The added code will add one (1) to the SharedVariable named "RuleTally".  This SharedVariable is a temporary variable that is stored in your session memory, so it is not saved in any document or to your hard drive.  Keep in mind, if any rule has multiple possible results, this code may have to be in multiple locations within the rule, so that it gets ran no matter the result of the rule.  The code for this would look something like this:

If SharedVariable.Exists("RuleTally") Then
	SharedVariable("RuleTally") = SharedVariable("RuleTally") + 1
End If

Then here is the code for the rule that creates the ProgressBar:

Dim oRules As Integer = 64 'or your maximum # of rules
Dim oProgressBar As Inventor.ProgressBar = ThisApplication.CreateProgressBar(False, oRules, "RUNNING RULES", True)
oProgressBar.Message = "Processing Rules..."

'Create a local Integer type variable to hold the tally value and check against each time
Dim oRuleTally As Integer = 0
'Create the SharedVariable named "RuleTally" and set its value to the Integer variable's value
SharedVariable("RuleTally") = oRuleTally

For oRuleTally = SharedVariable("RuleTally") To oRules
	If SharedVariable("RuleTally") > oRuleTally Then 'more rules have been processed
		oRuleTally = SharedVariable("RuleTally")
		oProgressBar.Message = "Processing Rule # " & oRuleTally & " Of " & oRules
		oProgressBar.UpdateProgress
	Else
		'wait for the tally to increase, then loop again
		System.Threading.Thread.Sleep(500) 'milliseconds (500 = half a second)
	End If
Next

'only close the ProgressBar if it reaches the max number (oRules) or more
If oRuleTally >= oRules Then
	oProgressBar.Message = "All Rules Have Been Processed."
	oProgressBar.Close
End If

   If the ProgressBar isn't going to work right for you, here's another similar idea you may be interested in.  You could simply update the "StatusBarText" String value to show the progress textually, without the ProgressBar.  You would still need to add the code to all the rules, but this may run smoother.  The code is similar:

Dim oRules As Integer = 64 'or your maximum # of rules
ThisApplication.StatusBarText = "Please Wait...Processing Rules..."

'Create a local Integer type variable to hold the tally value and check agains each time
Dim oRuleTally As Integer = 0
'Create the SharedVariable named "RuleTally" and set its value to the Integer variable's value
SharedVariable("RuleTally") = oRuleTally

For oRuleTally = SharedVariable("RuleTally") To oRules
	If SharedVariable("RuleTally") > oRuleTally Then 'more rules have been processed
		oRuleTally = SharedVariable("RuleTally")
		ThisApplication.StatusBarText = "Please Wait...Running Rule # " & oRuleTally & " Of " & oRules
	Else
		'wait for the tally to increase, then loop again
		System.Threading.Thread.Sleep(500) 'milliseconds (500 = half a second)
	End If
Next

If oRuleTally >= oRules Then
	ThisApplication.StatusBarText = "All Rules Have Been Processed."
End If

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

ahmed.hagi
Enthusiast
Enthusiast

Thank you so much for this.

 

So for this to work, I would just place the following code at various point in all the rules:

 

If SharedVariable.Exists("RuleTally") Then
SharedVariable("RuleTally") = SharedVariable("RuleTally") + 1
End If

 

And create a new rule that holds the progress code?

I don't need to define the shared variable in any of the other rules?

0 Likes