Running part level rules from external rule

Running part level rules from external rule

Anonymous
Not applicable
399 Views
3 Replies
Message 1 of 4

Running part level rules from external rule

Anonymous
Not applicable

Hi All,

 

I am looking for any help on Running part level rules from external rule

I have a Inventor assembly with around 50 parts. All 50 parts have ilogic rules written inside.

 

I need to run all the rules of the parts from external rule. I can do it by calling Individual rules (writing all 50), but Is there any single code that runs ALL the rules of parts in an assembly?

I am looking for code for that

 

Thanks

Rudresh

 

 

 

 

0 Likes
400 Views
3 Replies
Replies (3)
Message 2 of 4

bretrick30
Advocate
Advocate

How many levels is your assembly?

 

Is it

Assembly > Parts with rules

or

Assembly > Sub assembly > Part with rules

0 Likes
Message 3 of 4

Anonymous
Not applicable

Is the answer significantly different depending on how many levels there are to his assembly model?

0 Likes
Message 4 of 4

rjay75
Collaborator
Collaborator

If the rules on the parts are internal rules create an internal rule on each part that runs the rules inside the part. For instance I have rules that assemble individual parts. In each part I have a single update rule. This rule then runs the needed internal rules. So on each parts you need to just run a single rule.

 

What I do in my assembly rule is insert the part. Set any internal parameters to their values in the part. (I do this by having a 'base part' that contains only parameters that each part derives from using only the parameters so if the base is updated all parts that use those parameters get the new values applied to them. Then I have an Update internal rule on those parts so I only have to run the update rule which I can do in a For Each statement on each component occurrence. This way I don't have to know which parameters goes with each part. I just look for an update rule and run that.

 

Here's code that will cycle through all to components and subcomponents in an assembly and run an update rule named "UpdateRule" if found. It keeps track of documents it's run the rule on so it doesn't run the update rule more than once on the same document.

 

Sub Main()
	Dim docList As ArrayList = New ArrayList()
	For Each co As ComponentOccurrence In ThisDoc.Document.ComponentDefinition.Occurrences
		RunUpdateRule(co, docList)
	Next co			
End Sub

Sub RunUpdateRule (co As ComponentOccurrence, docs As ArrayList)
	Dim cDocName As String
	Dim cDoc As Document
	cDoc = co.ReferencedDocumentDescriptor.ReferencedDocument
	cDocName = cDoc.FullDocumentName
	If Not docs.Contains(cDocName) Then
		docs.Add(cDocName)
		If cDoc.DocumentType = kAssemblyDocumentObject Then
			For Each subCo As ComponentOccurrence In cDoc.ComponentDefinition.Occurrences
				RunUpdateRule(subCo, docs)
			Next subCo		
		End If
		Try
			iLogicVb.RunRule(co.Name, "UpdateRule")
		Catch ex As Exception
			'Do Nothing, Rule not found.
		End Try
	End If
End Sub

 

0 Likes