iLogic: how to do "regenerate all rules" for all open idw documents.

boris
Participant
Participant

iLogic: how to do "regenerate all rules" for all open idw documents.

boris
Participant
Participant

Hi, how to do "regenerate all rules" for all open idw documents with ilogic or vba?

 

I tried to make a rule but it doesn’t work

 

   Dim oDoc As Document

    For Each oDoc In ThisApplication.Documents.VisibleDocuments
        If oDoc.DocumentType = kDrawingDocumentObject Then
          
		  iLogicVb.UpdateWhenDone = True
		  
		  Dim controlDef As ControlDefinition = ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.RegenAllRules")
controlDef.Execute2(True)

		  
        End If
    Next oDoc

 

Thanks in advance!

0 Likes
Reply
Accepted solutions (2)
829 Views
7 Replies
Replies (7)

JhoelForshav
Mentor
Mentor

@boris 

Perhaps something like this? 🙂

 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		For Each oRule As iLogicRule In iLogicVb.Automation.Rules(oDoc)
			If oRule IsNot iLogicVb.Automation.GetRule(iLogicVb.RuleDocument, iLogicVb.RuleName) 'Make sure not to create an infinity loop!
				iLogicVb.Automation.RunRuleDirect(oRule)
			End If
		Next
	End If
Next
0 Likes

boris
Participant
Participant

Code not work 😞 inventor 2018

 

Rule Compile Errors in ilogic - update all opened documents with ilogic rules, in test.idw

Error on Line 4 : 'RuleName' is not a member of 'Autodesk.iLogic.Interfaces.ILowLevelSupport'.

 

What rule name should I enter?

 
0 Likes

JhoelForshav
Mentor
Mentor

Apparently RuleName method wasn't available in Inventor 2018. I cannot think of any other way to keep the rule from running itself over and over again if it exists in a drawing document then....

You could run it like this though... Just make sure not to run it from a drawing document!

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		For Each oRule As iLogicRule In iLogicVb.Automation.Rules(oDoc)
				iLogicVb.Automation.RunRuleDirect(oRule)
		Next
	End If
Next

 

JhoelForshav
Mentor
Mentor
Accepted solution

Or if you name your rule something specific and have that name hard coded in the rule like this maybe?

It's very important that you name the rule RegenRules in this case.

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		For Each oRule As iLogicRule In iLogicVb.Automation.Rules(oDoc)
			If oRule IsNot iLogicVb.Automation.GetRule(iLogicVb.RuleDocument, "RegenRules") 'Make sure not to create an infinity loop!
				iLogicVb.Automation.RunRuleDirect(oRule)
			End If
		Next
	End If
Next

 

Darkforce_the_ilogic_guy
Advisor
Advisor

are the rules on the doc or extranel rules?

0 Likes

boris
Participant
Participant

code works in new idw file 🙂

Thanks you.

 

What would such code look like for working with assemblies?

launching rules both in assembly and in subassemblies and parts.

 

 

 

 

 

 

 

 

0 Likes

boris
Participant
Participant
Accepted solution

create new.idw

create rule in new.idw

insert code 

For Each oDoc As Document In ThisApplication.Documents.VisibleDocuments
	If oDoc.DocumentType = kDrawingDocumentObject Then
		For Each oRule As iLogicRule In iLogicVb.Automation.Rules(oDoc)
				iLogicVb.Automation.RunRuleDirect(oRule)
		Next
	End If
Next

 run rule.

profit 🙂

0 Likes