iLogic code to enale Don't Run Automatically

iLogic code to enale Don't Run Automatically

planetoid127
Explorer Explorer
424 Views
6 Replies
Message 1 of 7

iLogic code to enale Don't Run Automatically

planetoid127
Explorer
Explorer

Good day,

I'm currently writing a script in iLogic that needs to be able to enable the Don't Run Automatically option within it's code.  I was therefore wondering if anyone is aware of how to enable this option using iLogic code.  Thanks!

Have a good day,

Jonathan

 

Screenshot 2023-10-23 082540.png

 

0 Likes
Accepted solutions (1)
425 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Try this:

Dim oRule As iLogicRule = iLogicVb.Automation.GetRule(ThisDoc.Document, "MyInternalRuleName")
oRule.AutomaticOnParamChange = False

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

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

planetoid127
Explorer
Explorer

Thank you very much!

0 Likes
Message 4 of 7

Jacob__with__a__k
Enthusiast
Enthusiast

hi!

 

here a rule that will go over all rules in you current document and all rules in all referenced documents

it changes following settings:

-Fire dependant rules Immediately

-Don't run automatically

-silent operation

because it's quite a big edit in possibly a lot of documents I included a popup so I wouldn't run it accidently (which happend before 🙂 )

 

Happy coding!

 

edit: @WCrihfield you beat me to it, with a far simpler answer 🙂

Public Class ThisRule
    Private iLogicAddinGuid As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
    Private iLogicAddin As ApplicationAddIn = Nothing
    Private iLogicAutomation = Nothing
	
	Private	ruleAutomaticOnParamChange As Boolean = False
	Private ruleFireDependentImmediately As Boolean = False
	Private ruleSilentOperation As Boolean = False
	
Sub Main()
	
'give a pop-up, so you won't run it on accident
controle = MessageBox.Show("this rule will change the settings for ALL rules in ALL parts in your assembly" & vbCrLf & _
"current settings:" & vbCrLf & _
" -run on parameter change = " & ruleAutomaticOnParamChange & vbCrLf & _
" -fire dependent rules immediantly = " & ruleFireDependentImmediately & vbCrLf & _
" -silent operation = " & ruleSilentOperation & vbCrLf & vbCrLf &  _
"do you confirm?", "edit all ilogic settings",MessageBoxButtons.YesNo)

If controle <> vbYes
	MsgBox("cancelled")
	Return
End If

'add ilogic addin
	iLogicAddin = ThisApplication.ApplicationAddIns.ItemById(
	"{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
	iLogicAutomation = iLogicAddin.Automation

Dim doc As Document = ThisDoc.Document

'run sub for current doc
searchDoc(doc)

'run sub for all referenced docs
If doc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject
	For Each refDoc As Document In doc.AllReferencedDocuments
		searchDoc(refDoc)
	Next
End If
MsgBox("done")
End Sub

Private Sub searchDoc(doc As Document)
    Dim rules = iLogicAutomation.Rules(doc)
    If (rules Is Nothing) Then Return
    For Each rule As iLogicRule In rules
		
		Try
			rule.AutomaticOnParamChange = ruleAutomaticOnParamChange
		Catch
		End Try
		
		Try
			rule.FireDependentImmediately = ruleFireDependentImmediately
		Catch
		End Try		
		
		Try
	      	        rule.SilentOperation = ruleSilentOperation
		Catch
		End Try
		
	Next
End Sub
End Class

 

Message 5 of 7

DonStauffer99
Advocate
Advocate

This works for .FireDependentImmediately as well, but I have one question.

It seems like setting this option on the currently running rule has no effect until the next time you run the rule. Is there a way I can engage the change immediately?

 

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @DonStauffer99.  It is difficult to understand what you mean here, but I am leaning towards saying no.  I do not recall ever wanting or needing to change any of those settings for an iLogic rule from within that rule's own code, expecting it to take effect while that rule is actually running.  I have changed general iLogic add-in settings, and the settings of other rules, from a different rule, then ran other rules from the one making the settings changes, then set settings back to the way they were before running the other rules.  I have learned from experience that when I create one or more custom event handlers with an external iLogic rule, I can not change how that rule works, while that rule is still running, and any changes I make to the contents of the rule it originated from, while that rule is still running, will only effect how it will work the next time it runs, but will not effect the currently 'running' instance.  This is because is seems like the moment we run an iLogic rule, its contents at that exact moment get copied up into Inventor's session memory, where it remains unchanged while it is 'active' or 'running'.  Because of this, I do not believe it would be possible for us to change those types of rule settings mid-run of a rule, and have them take effect before the rule finishes that same run.  But that is just my theory at this point.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

DonStauffer99
Advocate
Advocate

Not terribly important. I just have a rule which calls an external rule which should only be called by rules with .FireDependentImmediately = True, and this is in case I forget to set that.

0 Likes