Hi
Little help please. I would like to read some numeric value parameters and sum it up. I have a assembly which contains parts and sub assemblies. Some od them have parameter "wool". I would like to sum it up and place numeric value to parameter "sum_wool" in main assembly.
Any ideas? Some ilogic?
Solved! Go to Solution.
Hi
Little help please. I would like to read some numeric value parameters and sum it up. I have a assembly which contains parts and sub assemblies. Some od them have parameter "wool". I would like to sum it up and place numeric value to parameter "sum_wool" in main assembly.
Any ideas? Some ilogic?
Solved! Go to Solution.
Solved by gcoombridge. Go to Solution.
Hello @pbartosinski,
iLogic code can help without doubt, but if there are not many components with that parameter, then, you can directly Link the component parameter to the top assembly directly as a reference one. After that, just make a new wood_sum to sum up the total value.
Go to top assembly and click Fx, link button and select the component and find the parameter to link.
Hope it helps a little bit.
Hello @pbartosinski,
iLogic code can help without doubt, but if there are not many components with that parameter, then, you can directly Link the component parameter to the top assembly directly as a reference one. After that, just make a new wood_sum to sum up the total value.
Go to top assembly and click Fx, link button and select the component and find the parameter to link.
Hope it helps a little bit.
If only the parts will have the 'wool' parameter and not the sub-assemblies use this. It will return all parts inside sub-assemblies, just not the sub-assembly itself.
Dim oDoc As AssemblyDocument oDoc = ThisDoc.Document Dim oOcc As ComponentOccurrence 'parameter called sum_wool already created in parameter box sum_wool = 0 For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences Try sum_wool = sum_wool + Parameter(oOcc.Name, "wool") Catch 'Do Nothing End Try Next oOcc
If only the parts will have the 'wool' parameter and not the sub-assemblies use this. It will return all parts inside sub-assemblies, just not the sub-assembly itself.
Dim oDoc As AssemblyDocument oDoc = ThisDoc.Document Dim oOcc As ComponentOccurrence 'parameter called sum_wool already created in parameter box sum_wool = 0 For Each oOcc In oDoc.ComponentDefinition.Occurrences.AllLeafOccurrences Try sum_wool = sum_wool + Parameter(oOcc.Name, "wool") Catch 'Do Nothing End Try Next oOcc
This one if the sub-assembly might have the parameter. Both codes are just adjusted from this blog post: https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html which covers the subject really well
Sub Main SumWoolSub() sum_wool =0 Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument SumWoolSub(oAsmDoc.ComponentDefinition.Occurrences, 1) End Sub Private Sub SumWoolSub(Occurrences As ComponentOccurrences, _ Level As Integer) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences Try sum_wool = sum_wool + Parameter(oOcc.Name, "wool") Catch 'Do Nothing End Try If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then SumWoolSub(oOcc.SubOccurrences, Level + 1) End If Next End Sub
This one if the sub-assembly might have the parameter. Both codes are just adjusted from this blog post: https://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html which covers the subject really well
Sub Main SumWoolSub() sum_wool =0 Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument SumWoolSub(oAsmDoc.ComponentDefinition.Occurrences, 1) End Sub Private Sub SumWoolSub(Occurrences As ComponentOccurrences, _ Level As Integer) Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences Try sum_wool = sum_wool + Parameter(oOcc.Name, "wool") Catch 'Do Nothing End Try If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then SumWoolSub(oOcc.SubOccurrences, Level + 1) End If Next End Sub
Works perfectly. Thank you!
Works perfectly. Thank you!
Can't find what you're looking for? Ask the community or share your knowledge.