Limit duration time of external iLocic rule execution

Limit duration time of external iLocic rule execution

Maxim-CADman77
Advisor Advisor
1,532 Views
12 Replies
Message 1 of 13

Limit duration time of external iLocic rule execution

Maxim-CADman77
Advisor
Advisor

I've created a set of iLogic rules for checking Inventor documents against local corporate standards and a single aggregator iLogic rule which initiate run of rules and collect check results in a kind of a report.

But execution of some rules on some documents may take quite a long time which I like to prevent.

AFAIK iLogic rule can't abort itself according to some given duration time limit, right?

I'd like to know whether parent (aggregator) iLogic rule can abort execution of its child iLogic if it is running longer than it is allowed (and if yes then how)?

Thanks in advance.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
1,533 Views
12 Replies
Replies (12)
Message 2 of 13

Maxim-CADman77
Advisor
Advisor

Not possible?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 3 of 13

JaneFan
Autodesk
Autodesk

As I know, it is not supported in iLogic to abort the rule execution in parent rule, either.




Jane Fan
Inventor/Fusion QA Engineer
0 Likes
Message 4 of 13

MjDeck
Autodesk
Autodesk
Accepted solution

iLogic doesn't provide functions or UI to make this easy to do. But you can add code to a rule to make it end after a specified time. Here's a sample:

Dim startTime = Now

For i = 1 To 10
	Threading.Thread.Sleep(1000)
	Dim timeDiff As TimeSpan = Now - startTime
	If timeDiff.TotalSeconds > 5 Then
		MessageBox.Show("Time is up", "Check")
		Return ' Exit the rule
	End If		
Next

Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 5 of 13

DRoam
Mentor
Mentor

From your parent rule you can create a Shared Variable for the timeout time. Each for your child rules can check, at various checkpoints, if "now" is greater than the timeout time. If it is, they can exit. In your parent rule, you'll also want to check between each child rule, so it can stop running subsequent rules. Overall, this might look something like this:

 

Parent rule:

(EDIT: I edited this so that it will remove the shared timeout variable before a timeout exit)

Sub Main()
Dim oTimeout As DateTime = Now.AddSeconds(60)
SharedVariable("Timeout") = oTimeout

iLogicVb.RunExternalRule("Rule1")

If TimeExpired Then Goto MyExit
iLogicVb.RunExternalRule("Rule2")

If TimeExpired Then Goto MyExit
iLogicVb.RunExternalRule("Rule3")

MyExit:
SharedVariable.Remove("Timeout")
Return

End Sub

Function TimeExpired As Boolean
	If SharedVariable.Exists("Timeout") Then
		Return ( Now > SharedVariable("Timeout") )
	Else
		Return False
	End If
End Function

Child rules:

Sub Main()

For i = 1 To TaskCount
	If TimeExpired Then Return
	
	'Do task
Next

End Sub

Function TimeExpired As Boolean
	If SharedVariable.Exists("Timeout") Then
		Return ( Now > SharedVariable("Timeout") )
	Else
		Return False
	End If
End Function

 

0 Likes
Message 6 of 13

DRoam
Mentor
Mentor

You could also try using a progress bar with a cancel button. I think this would work, but it would only be able to bail out from the parent rule, between each child rule. It wouldn't be able to stop operation within a child rule. You could try this and see how it works for you:

 

(If you run this as-is you can see a sample of how it works).

Sub Main()
'~~~~~Progresss bar setup~~~~~
Dim oTitle As String = "Progress Bar Title"
Dim OpsCount As Integer = 9 '<--- CHANGE TO YOUR # OF CHILD RULES BEING FIRED
Dim oDebugDelay As Integer = 1000 '<--- CHANGE TO ZERO WHEN TESTING WITH YOUR CHILD RULES

'~~~~~Initiate progress bar~~~~~
TotalOpsCount = OpsCount + 1 'Adds "Finishing..." operation
Dim oProgressBar As Inventor.ProgressBar = ThisApplication.CreateProgressBar(False,TotalOpsCount,oTitle,True)
	AddHandler oProgressBar.OnCancel, AddressOf ProgressBarCancel
	CurrentOp = -1
	ContinueProcess = True
	ProgressBarUpdate(oProgressBar,"Loading...",oDebugDelay)
	
	'~~~~~~~~~~~~~Replace this:~~~~~~~~~~~~~
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	For i = 1 To TotalOpsCount - 1
		If ContinueProcess = False Then Exit For
		ProgressBarUpdate(oProgressBar,"Processing...",oDebugDelay)
	Next
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	'~~~~~...with something like this:~~~~~~
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'	iLogicVb.RunExternalRule("Rule1")
'
'	If ContinueProcess = False Then Goto MyExit
'	iLogicVb.RunExternalRule("Rule2")
'	
'	If ContinueProcess = False Then Goto MyExit
'	iLogicVb.RunExternalRule("Rule3")
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	
	MyExit:
	ProgressBarUpdate(oProgressBar,"Finishing...",oDebugDelay)
oProgressBar.Close
End Sub

Private ContinueProcess As Boolean
Private CurrentOp As Integer 
Private TotalOpsCount As Integer

Sub ProgressBarUpdate(oProgressBar As Inventor.ProgressBar, oMessage As String,Optional oDebugDelay As Integer = 0)
	CurrentOp = CurrentOp + 1
	Dim PercentComplete As Integer = CurrentOp/(TotalOpsCount) * 100
	oProgressBar.Message = oMessage & vbCrLf & "Percent complete: " & PercentComplete & "%"
	oProgressBar.UpdateProgress
	System.Threading.Thread.Sleep(oDebugDelay)
End Sub 'Progress bar update

Sub ProgressBarCancel
	MessageBox.Show("Process cancelled.","",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
	ContinueProcess = False
End Sub
Message 7 of 13

Maxim-CADman77
Advisor
Advisor

Thank you for the idea but I don't see how can I apply it on a check like this

Dim stopWatch As New Stopwatch()
stopWatch.Start()

Dim res_status As String="PASS"
Dim oSB As SurfaceBody=ThisDoc.Document.ComponentDefinition.SurfaceBodies(1)

If Not oSB.IsEntityValid(oSB.FaceShells(1), 5, pr) Then res_status="FAIL"

stopWatch.Stop()
Dim ts As TimeSpan=stopWatch.Elapsed
Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)

MsgBox(res_status ,,"Duration Time:"& elapsedTime)

Which being run on the 3D like attached lasts for about 1-2 minutes depending on the PC configuration.

 

Is it possible to break it let say after 15 seconds?

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 8 of 13

DRoam
Mentor
Mentor

I don't think we have the ability to interrupt iLogic mid-execution of an operation (single line). Mike may know of one, but I don't.

 

But if you're doing this operation multiple times, then you can use the progress bar and you should be able to cancel between operations by checking the "ContinueOperation" boolean between each operation. But it'll always have to finish executing the current line before it can respond to the cancel event. So if it takes 2 minutes to execute the IsEntityValid line, you'll just have to wait 2 minutes for it to cancel. But at least it won't keep going after that.

 

Doesn't help you much now, but you could also vote for this functionality request: ESC key stop iLogic Script.

0 Likes
Message 9 of 13

DRoam
Mentor
Mentor

Another thing you could do is, if you know certain parts will be a problem, create a boolean iProperty in them called something like "SkipDuringCheck" and set it to True. Then have your iLogic code check for this before processing each part.

 

You could even have your iLogic automatically set this to True if it takes more than 15 seconds to process a part. That way, any "heavy" parts you missed tagging manually will be processed once, but never again.

 

This would also give you a good way to scroll through the BOM and see which parts are marked as "Skip" and therefore not being processed by your rule.

0 Likes
Message 10 of 13

MjDeck
Autodesk
Autodesk

I found that you can get the IsEntityValid check on that sample part (B119RQ11111(LongTopoCheck)) to run instantaneously by "re-making" the coil feature. Rebuild All isn't sufficient. But this is: edit the feature and change the Coil Size > Revolution to 5.1 ul. Then change it back to 5.0.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 11 of 13

Maxim-CADman77
Advisor
Advisor

Mike,
I do confirm that after "refreshing" the sample model* with changing the parameter twice the topology check** returns FAIL pretty fast (>0,2sec) ...

BUT

I'm searching some general solution (total check of the company's Vault content reveals considerable check delays on Inventor documents of different types with a batch of checks I've created).

For example I do have a sample of a IAM where check of positional representation lasts for about 4 minutes (because of the fact that each of the two PosRep activation takes about 2 minutes).

Thus if there is any way to break single line of iLogic I'd like to know about it.

 

Anyway thank you for debugging the IPT.

 

* In fact the original model is  a bit more complex and was simplified to a single feature by me to be able share it here.

** The real check is also a bit more complex and does contain some cycles. I've simplified it to make it clear that interrupting cycles is not a solution of the issue.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 12 of 13

MjDeck
Autodesk
Autodesk

There is currently no way to interrupt a single API or iLogic call.
If you start running checks on all documents but then you interrupt the process, you'll have missing data. The checks won't be complete. Maybe instead of interrupting, you can run the tests on a dedicated machine and let them go as long as necessary? Also, you could log the results to a file that is flushed often. Then you can open that file to look at the results so far.


Mike Deck
Software Developer
Autodesk, Inc.

0 Likes
Message 13 of 13

Maxim-CADman77
Advisor
Advisor
Yeah. I'm already doing it all as you've described.

But I also want the add-in we created (as a replace to the buggy Inventor Design Checker) don't interupt the work process of our designers (it forces check of all explisitly open InvDocs just after open and before save, also if initiated by special button).
For 99,99% of InvDocs check with a batch of our iLogic rules takes 3~5sec (which is ok) but that 0,01% of documents that checks for 15+ seconds annoy designers drastically.
Thats why I've created this thread.
But now I see - the is no miracle... We need to teach how to live with what we have.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes