• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Customization

    Reply
    Mentor
    Posts: 152
    Registered: ‎11-30-2007
    Accepted Solution

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

    282 Views, 6 Replies
    10-26-2012 06:49 AM

    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
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,933
    Registered: ‎03-08-2006

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

    10-26-2012 08:30 AM in reply to: tuliobarata

    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
    
    

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Mentor
    Posts: 152
    Registered: ‎11-30-2007

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

    10-26-2012 09:19 AM in reply to: Curtis_Waguespack

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

     

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

    the problem is to validate if have or no the  property, i tried if xxxx=true, or just like below, and nothn :smileysad:

    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
    Please use plain text.
    *Expert Elite*
    Curtis_Waguespack
    Posts: 1,933
    Registered: ‎03-08-2006

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

    10-26-2012 10:46 AM in reply to: tuliobarata

    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

     



      solution.png  Did you find this reply helpful ? If so please use the Accept as Solution or  Kudos button below.

    Please use plain text.
    Mentor
    Posts: 152
    Registered: ‎11-30-2007

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

    10-26-2012 11:42 AM in reply to: Curtis_Waguespack

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

     

    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
    Please use plain text.
    Mentor
    Posts: 152
    Registered: ‎11-30-2007

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

    10-26-2012 11:52 AM 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
    Please use plain text.
    Mentor
    Posts: 152
    Registered: ‎11-30-2007

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

    10-30-2012 12:45 PM in reply to: tuliobarata

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

     

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

     

     

    Thanks

    Túlio Barata

    IV 2013
    Please use plain text.