Autodesk Inventor Customization
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi all!
I got here on in my templates, two types of weight - net and gross. I've changed the main property MASS of each PART to be the GROSS weight, so when i have one assembly i always get the total gross weight.
And when i wanna get the NET, I open the BOM, show the proper column with this net weight and then export do XLS to sum all of then..
Now the doubt is, to get the things easier, is there a way to put some code in the assemblies, that could sum all the properties "X" from each part and sub assemblie to get the total net weight ?
i posted here too, maybe its easier then in the other section.
Thanks!
Túlio Barata
Solved! Go to Solution.
Re: iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi tuliobarata,
This snippet looks for a custom iProperty called "MyNumber" in all of the assembly occurences and then sums them into the custom iProperty called "MyNumber" in the assembly.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'clear the custom property in the assembly
iProperties.Value("Custom", "MyNumber") = 0
'set a reference to the assembly component definintion.
'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
'(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
'custom property in the assembly
xNumber = iProperties.Value("Custom", "MyNumber")
'custom property in the parts
yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MyNumber")
sumNumber = xNumber + yNumber
'set custom property values
iProperties.Value("Custom", "MyNumber") = sumNumber
Else
End If
Next

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Re: iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Curtis, just perfect! Thanks very much for the fast reply!
Worked very well with this code!
And sorry, but It just linked me to another doubt ![]()
The code is working perfectly on my templates that i got my custom property, but if the assembly got any other part, from CC i.e. thaa doesnt have this custom property ? then i shoul sum with the original mass of that part.
So how can i make a division if dont have the custom property, to sum with the mass of the part ? cuz i guess its easier then change all the CC files to add this property...
I tried just to verify with an IF, but didnt work ![]()
the problem is to validate if have or no the property, i tried if xxxx=true, or just like below, and nothn ![]()
like this:
'clear the custom property in the assembly iProperties.Value("Custom", "pLiquido") = 0 'set a reference to the assembly component definintion.'This assumes an assembly document is open.Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition 'Iterate through all of the occurrencesDim oOccurrence As ComponentOccurrence For Each oOccurrence In oAsmCompDef.Occurrences 'check for and skip virtual components'(in case a virtual component trips things up)If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then 'custom property in the assembly xNumber = iProperties.Value("Custom", "pLiquido") 'custom property in the parts
'changed this part only ***************************************************
If iProperties.Value(oOccurrence.Name, "Custom", "pLiquido") Then yNumber = iProperties.Value(oOccurrence.Name, "Custom", "pLiquido") sumNumber = xNumber + yNumber Else yNumber = iProperties.Mass sumNumber = xNumber + yNumber End If
'till here***************************************************************
'set custom property valuesiProperties.Value("Custom", "pLiquido") = sumNumber Else End If
Thanks very much again,
Túlio Barata
Re: iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi tuliobarata,
Using my example, here is some code to check for an existing iProperty and add it (ad a number) if not found.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
'- - - - - - - - - - - find or create custom iProperty - - - - - - - - - -
'Define the open document
Dim openDoc As Document
openDoc = ThisDoc.Document
'Look at all of the files referenced in the open document
Dim docFile As Document
For Each docFile In openDoc.AllReferencedDocuments
Dim propertyName1 As String = "MyNumber"
'define custom property collection
oCustomPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
Try
'look for property
oProp = oCustomPropertySet.Item(propertyName1)
Catch
' Assume error means not found so create it
oCustomPropertySet.Add(0, propertyName1)
End Try
Next
'- - - - - - - - - - - sum the custom iProperty - - - - - - - - - -
'clear the custom property in the assembly
iProperties.Value("Custom", "MyNumber") = 0
'set a reference to the assembly component definintion.
'This assumes an assembly document is open.
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
'check for and skip virtual components
'(in case a virtual component trips things up)
If Not TypeOf oOccurrence.Definition Is VirtualComponentDefinition Then
'custom property in the assembly
xNumber = iProperties.Value("Custom", "MyNumber")
'custom property in the parts
yNumber = iProperties.Value(oOccurrence.Name, "Custom", "MyNumber")
sumNumber = xNumber + yNumber
'set custom property values
iProperties.Value("Custom", "MyNumber") = sumNumber
Else
End If
Next

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Re: iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Great Curtis! Thanks again!
Now the code is working 100%, i just changed, instead of create the property it uses the standard mass of the ocurrences, now its nice ![]()
One more doubt Curtis, do u know that if i have one assembly with one more sub assembly(that has other sub assembly inside it). total of3 levels of assemblies with some parts inside... Considering that all the assemblies will have this rule. This code will get all the properties of all sub parts ?
Or, ill have to enter in the 3º assy, run the rule....open the 2º abd run and then open the 1ºand run to get the real net weight ?
Thanks very much for the help!
Re: iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
I just tried here, and it not update all the net weight, i tested with 3 levels of assemblies, and when I run the rule one by one manually, the main assy gets the net weight perfectly!
but if i change anything in any sub assy and dont run the rule, or if i change things in the 3º assy, fun the rule, but dont run the rule of the 2º assy, the 1º assy dont get the real weight....
so now the question is, is there a way to run this rule in each sub assy active in the mani assembly ?
Thanks Again!
Re: iLogic - How to sum a property of all sub assembli.. .
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
i was reading some stuffs on API Help, but all my ideas untill now were useless. Just got error messages... ![]()
still trying, if someone know a way to make it work plz give me some light ![]()
Thanks
Túlio Barata

