Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - How to sum a property of all sub assembli...

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
tuliobarata
5437 Views, 9 Replies

iLogic - How to sum a property of all sub assembli...

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

IV 2013
IV 2013
9 REPLIES 9
Message 2 of 10

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

 

Message 3 of 10

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 :S

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

IV 2013
Message 4 of 10

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

 

Message 5 of 10

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!

 

IV 2013
Message 6 of 10
tuliobarata
in reply to: tuliobarata

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!

IV 2013
Message 7 of 10
tuliobarata
in reply to: tuliobarata

i was reading some stuffs on API Help, but all my ideas untill now were useless. Just got error messages... :S

 

still trying, if someone know a way to make it work plz give me some light 🙂

 

 

Thanks

Túlio Barata

IV 2013
Message 8 of 10
JachinMK
in reply to: tuliobarata

Curtis, 

 

is there a way to use the sample code you posted but make it work only for assembly's?

in other words. I have a parameter in each subassembly that i want to sum in the top assembly. I would like the rule to get the value only from the subassembly's. It will then skipp all parts. 

 

I tried some way's but did not get it working.

 

Thanks,

Jachin

Message 9 of 10

Hi Curtis,

i ask for a solution, that the code also runs through subassemblys and sums the parts? For example, i have a part A and i change the value "MyNumer" - this part A is stored in the main assembly and in an subassembly. The code gets only the value of the part A in the mainassembly not from the Sub.

Hopefully there is a chance....

Regards

Martin

Message 10 of 10
arge
in reply to: Curtis_Waguespack

hi curtis

 

My rule subject ;  custom properties of the all parts in assembly. Miscalculating assemblies built with some methods. Examples in JPEG files.

 

What could be the reason? help please  thanksdemote create1.jpgdemote create2.jpgdemote create3.jpgdragging create 1.jpgdragging create 2.jpgdragging create 3.jpgdragging create 4.jpgdragging in place create 1.jpgdragging in place create 2.jpgplace create 1.jpgplace create 2.jpgplace create 3.jpgplace create 4.jpgrun  Rule for all assembly.jpg

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report