How to write an iLogic rule that would...

chris
Advisor
Advisor

How to write an iLogic rule that would...

chris
Advisor
Advisor

I'm trying to write an iLoigc rule that would look at all the parts in an assembly and for any part or sub-assembly within the top-level assembly that contains the custom iProperty "STATE", it would make that iProperty value equal to the Top Level assembly value of the same name.

 

Example: the top level assembly contains custom iProperty called "STATE"

 

the top level assembly is made up of two sub-assemblies, each with 3 parts, as well as two single parts at the top level. the two sub-assemlbies contain the same custom iProperty "STATE" as well as each of their parts and the two single parts.

 

I can do all this manually and make it work, but I'm hoping there is a way to just have iLogic look at the sub-assemblies and top level assembly and add each of their parts to an iLogic rule that looks something like this: (but instead of me manually typing in the components, iLogic would gather the list and set the components parameter "STATE" to equal the top level assemblies parameter "STATE"

 

Parameter("Sub_Assy1:1", "STATE") = STATE
Parameter("Sub_Assy2:1", "STATE") = STATE
Parameter("Single_Part1:1", "STATE") = STATE
Parameter("Single_Part2:1", "STATE") = STATE

0 Likes
Reply
Accepted solutions (2)
515 Views
6 Replies
Replies (6)

Michael.Navara
Advisor
Advisor
Accepted solution

You can iterate all occurrences at the top level assembly and try to set the parameter

Dim topAsm As AssemblyDocument = ThisDoc.Document
Dim topLevelState = Parameter.Value("STATE")

For Each occ As ComponentOccurrence In topAsm.ComponentDefinition.Occurrences
	Try
		Parameter.Value(occ.Name, "STATE") = topLevelState
	Catch
		' Ignore missing parameter
	End Try
Next

chris
Advisor
Advisor

@Michael.Navara This worked great, but I have one request, could you change it so that it will also look into sub-assembly parts and change those as well?

 

For example, if I have 3 loose parts and one sub-assembly at the top level, it's changing those parameters as written, but it's not reaching the components of the sub-assembly... (I'm not sure if that is possible)

0 Likes

chris
Advisor
Advisor

Here's a better example: the ones in red changed with your current rule, but I'd like to see the ones in yellow change as well, without having to go into that sub-assembly to rule the current rule. 

chris_0-1712934088896.png

 

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @chris 


here is a quick example using Michael.Navara example to go through all levels

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Sub Main

	Dim topAsm As AssemblyDocument = ThisDoc.Document
	Dim topLevelState = Parameter.Value("STATE")
	Dim oOccs As ComponentOccurrences = topAsm.ComponentDefinition.Occurrences

	Call TraverseAssembly(oOccs, topLevelState)

End Sub

Function TraverseAssembly(oOccs As ComponentOccurrences, topLevelState As String)

	Dim oOcc As ComponentOccurrence
	Dim oDoc As Document
	Dim oUsereParams As UserParameters

	For Each oOcc In oOccs

		oDoc = oOcc.Definition.Document
		oUsereParams = oDoc.ComponentDefinition.Parameters.UserParameters

		Try
			Parameter.Value(oOcc.Name, "STATE") = topLevelState
		Catch
			oUsereParams.AddByValue("STATE", topLevelState, UnitsTypeEnum.kTextUnits)
		End Try


		If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then

			Call TraverseAssembly(oOcc.SubOccurrences, topLevelState)
		Else 'do stuff here for parts only

		End If
	Next

End Function

 

 

 

0 Likes

A.Acheson
Mentor
Mentor

Hi @chris 

See this article on traversing assemblies. You have two options work with parts only and there leaf occurrences this is the shortest and most direct code or traverse the whole assembly using a recursive loop see assembly structure. 

 

I would suggest you take each sample in that article and do a quick test. If you get a handle on what each one does you will have learned some of the more difficult concepts to get your ahead around. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan

chris
Advisor
Advisor

@Curtis_Waguespack  @Michael.Navara  thank to both of you for the assistance, this is working great. We have a bunch of legacy models and drawings that someone did years ago, but they treated Inventor like it was AutoCAD, so they have a bunch of "states" for each sub-assembly parts on different views and drawings, this will allow me to update them all at once instead of manually doing it 20X for 200+ drawings!!