I logic rule to find a sub assembly parameter and total them up

I logic rule to find a sub assembly parameter and total them up

Anthony5375F
Contributor Contributor
261 Views
3 Replies
Message 1 of 4

I logic rule to find a sub assembly parameter and total them up

Anthony5375F
Contributor
Contributor

Hi there, 

 

Apologies as i am new to i-logic and find it fascinating but complex. 

 

I currently have built assemblies which have i - logic code that shows "Total Cost" and " Cubic meter"  of each item. I then want to create a main assembly which these files are placed into, and wondered if there is an i-logic rule that can search all placed assemblies for that parameter then give me a total cost/ cubic meter within that assembly. 

 

i have attached a screen shot showing how i currently manually add my assemblies  parameters for reference

 

Thank you for your time 

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

dalton98
Collaborator
Collaborator

This rule does that. I wasnt sure what your parameter value was for cost so I just used "Cost". This also only looks at part components so it doesn't pull info from assembly files. lmk if you have any questions

Also, I find it easier to use custom iproperties instead of parameters when using rules like this, so thats another option.

Dim oAss As AssemblyDocument = ThisApplication.ActiveDocument
Dim oPartOccs As ComponentOccurrencesEnumerator
oPartOccs = oAss.ComponentDefinition.Occurrences.AllLeafOccurrences
Dim oPartOcc As ComponentOccurrence
Dim totalCost As Double = 0
Dim totalVolume As Double = 0

For Each oPartOcc In oPartOccs
	Dim oPartDoc As PartDocument
	oPartDoc = oPartOcc.Definition.Document
	Dim oUserParam As UserParameters
	oUserParam = oPartDoc.ComponentDefinition.Parameters.UserParameters
	Dim partCost As Double
	Dim partVolume As Double
	
	Try
		partCost = oUserParam.Item("Cost").Value
		partVolume = oUserParam.Item("CUBIC_M").Value
		totalCost = totalCost + partCost
		totalVolume = totalVolume + partVolume
		MessageBox.Show(totalVolume)

	Catch
		'param doesnt exist
	End Try
	
Next

MessageBox.Show(totalCost)
MessageBox.Show(totalVolume)

Try
oAss.ComponentDefinition.Parameters.UserParameters.Item("Cost").Value = totalCost
Catch
oAss.ComponentDefinition.Parameters.UserParameters.AddByValue("Cost", totalCost, UnitsTypeEnum.kUnitlessUnits)
End Try

Try
oAss.ComponentDefinition.Parameters.UserParameters.Item("CUBIC_M").Value = totalVolume / 2
Catch
oAss.ComponentDefinition.Parameters.UserParameters.AddByValue("CUBIC_M", totalVolume / 2, "m m m")
End Try

 

0 Likes
Message 3 of 4

Anthony5375F
Contributor
Contributor

Thank you for getting back to me. 

I am getting an error code pop up (attached). My current construction is as follows:

Parts within an assembly that contain all my parameters. Then my assembly has the total qty of material reading the parts parameters. I then have these parts within a main assembly. Is there a way for my main assembly to read the placed in assembly parameters only? I mean the way you have shown would do the same thing thinking about it. 

I am new to i logic and have only really scratched the surface. I am currently pre build large areas that are fully adjustable with it updated the total qtys i am after. 

 

I hope this makes sense thank you again 

0 Likes
Message 4 of 4

dalton98
Collaborator
Collaborator

I would need more info on the rule, the error is vague. And if you just want the top level components of the main assembly delete '.AllLeafOccurrences' and replace 'PartDocument' with 'Document' in the code I posted.

 

If you wanted to filter for assembly documents you can use an if statement for DocumentType

Dim oAss As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Document = oAss.ComponentDefinition.Occurrences.Item(2).Definition.Document
If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject
	MessageBox.Show("Message", "Title")
	'continue
End If

 

0 Likes