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

    Autodesk Inventor

    Reply
    Distinguished Contributor
    Posts: 130
    Registered: ‎06-12-2007
    Accepted Solution

    Part Quantities

    591 Views, 35 Replies
    01-18-2013 09:31 AM

    Our individual part drawings reference the quantity of that part used in an assembly.  Is there any way to get the quantity number for a part from an assembly and insert it in the individual part drawing?  Currently I manually put this in but sometimes I forget to do this or I enter an incorrect number.

     

    I haven't been able to find anyway to do this but any ideas on how to do this to keep my opportunites to make a mistake to a minimum?

    Stuart Kinzel
    Inventor 2013-64bit, HP EliteBook8740w Intel Core i5CPU 2.67 GHz
    8GB memory
    Windows 7 64bit
    Please use plain text.
    *Expert Elite*
    Posts: 727
    Registered: ‎09-03-2008

    Re: Part Quantities

    01-18-2013 09:55 AM in reply to: SKinzel

    You could probably do this with iLogic.  I can look into the code required to do this, if you think an iLogic solution is acceptable.

     

    -cwhetten

    Please use plain text.
    *Expert Elite*
    Posts: 727
    Registered: ‎09-03-2008

    Re: Part Quantities

    01-18-2013 10:30 AM in reply to: SKinzel

    It wasn't too hard, so I did it anyway.  You will probably want to create a custom iProperty in the part to store the value of the assembly quantity.  For example, if your assembly number is 4100, then you could create a custom iProperty called "4100_QTY" (you'll want to name your custom iProperty with some kind of reference to the assembly into which it is placed, since this part may be in multiple assemblies in different quantities).  Then in your assembly, you would have an iLogic rule that has the following code:

     

    iProperties.Value("ComponentName:1", "Custom", "4100_QTY") = ThisBOM.CalculateQuantity("Model Data", "ComponentName:1")

    Of course, change the "ComponentName:1" value to whatever your part is named in your assembly browser.  You'll have to make sure this rule is run if you make any changes to your assembly, so that the quantity value stored in each part is always up-to-date.  You could use event triggers for this, or some other method, or just remember to manually run your rule before you update your drawings.

     

    You will have a similar line of code for each component you wish to treat this way.

     

    -cwhetten

    Please click "Accept as Solution" if this response answers your question.

    Please use plain text.
    Distinguished Contributor
    Posts: 130
    Registered: ‎06-12-2007

    Re: Part Quantities

    01-18-2013 10:36 AM in reply to: SKinzel

    Thank you.  I'm just starting to learn about iLogic.  I'll try this out. 

     

    As I understand it the rule is in the ASSEMBLY and will need to be triggered.  I am thinking that maybe the rule would be triggered on any SAVE of the assembly.  Then when I open the part drawing it should automatically update, correct?

    Stuart Kinzel
    Inventor 2013-64bit, HP EliteBook8740w Intel Core i5CPU 2.67 GHz
    8GB memory
    Windows 7 64bit
    Please use plain text.
    *Expert Elite*
    Posts: 727
    Registered: ‎09-03-2008

    Re: Part Quantities

    01-18-2013 12:51 PM in reply to: SKinzel

    Yes, that would work.  You should set it to trigger BEFORE a save event, so that it saves the documents with the updated numbers.

     

    Event Trigger - Before Save.PNG

     

    -cwhetten

    Please click "Accept as Solution" if this response answers your question.

    Please use plain text.
    Mentor
    rhasell
    Posts: 194
    Registered: ‎05-23-2007

    Re: Part Quantities

    01-20-2013 03:39 PM in reply to: cwhetten

    Hi

     

    I just tested the iLogoc code, pretty cool, It might become painful with a few hundred parts though, perhaps I missed something?

     

    Up until now when I have needed this particular feature, is to just to it manually, using a copy and paste.

     

     

    Also having the custom field in the Assembly, highlight the entire QTY column, and copy it to the new custom column. It is still a manual process which is succeptable to errors, but pretty quick to do.

     

    Regards
    Reg

    Autodesk Product Design Suite Premium 2013 sp1.1 (1)
    Intel Core i7 (950@3.07GHz)
    Windows 7x64 (Home)
    12GB Ram
    Nvidia GeForce GTX 560 Ti (1Gig - Ver:314.07)
    Please use plain text.
    *Expert Elite*
    Posts: 727
    Registered: ‎09-03-2008

    Re: Part Quantities

    01-21-2013 10:41 AM in reply to: rhasell

    You're right, having to add a line for each component is a pain, and you would have to remember to add new lines or remove lines if you add or remove components from your assembly.  Not ideal.

     

    With that in mind, I modified the code to take care of these issues.  Here it is:

     

    '****************************


    oCompDef = ThisDoc.Document.ComponentDefinition
    Dim oCompOcc As Inventor.ComponentOccurrence

    'get the part number of this assembly and use it to build the name of a custom property, i.e. "4100_QTY"
    customPropertyName = CStr(iProperties.Value("Project", "Part Number")) & "_QTY"

    'loop through each component in this assembly
    For Each oCompOcc In oCompDef.Occurrences
        oCompName = oCompOcc.Name
        
        'get the part number of the current occurrence
        oCompPartNumber = oCompOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
        
        customPropertySet = oCompOcc.Definition.Document.PropertySets.Item("Inventor User Defined Properties")
        
        'test if the custom property already exists
        Try
            prop = customPropertySet.Item(customPropertyName)
        Catch
            'assume error means iProperty doesn't exist, so create the property
            customPropertySet.Add(0, customPropertyName)
        End Try
        
        'set the value of the custom property in the current occurrence to equal its quantity in the assembly
        iProperties.Value(oCompName, "Custom", customPropertyName) = ThisBOM.CalculateQuantity("Model Data", oCompPartNumber)
    Next

    iLogicVb.UpdateWhenDone = True

    '****************************

    This new code will work no matter how many components are in the assembly, and even works (without modification) when you add or remove components.

     

    I wrote it to build the name of the custom iProperty based on the part number of the assembly that contains the rule.  So, like in the example I mentioned earlier, if your assembly part number is 4100, then this code will take that value and create a custom iProperty called 4100_QTY.  You can modify this to be whatever you wish.  If you aren't sure how to do that, just ask and I can help you modify the code.

     

    This rule is flexible enough that you can copy and paste it into any of your assemblies without modifying the code.

     

    -cwhetten

    Please click "Accept as Solution" if this response answers your question.

     

    Please use plain text.
    Distinguished Contributor
    Posts: 130
    Registered: ‎06-12-2007

    Re: Part Quantities

    01-21-2013 10:44 AM in reply to: SKinzel

    Thanks.  I'm definately going to give this a try.  It might be a couple of weeks before I get time to play with it.

    Stuart Kinzel
    Inventor 2013-64bit, HP EliteBook8740w Intel Core i5CPU 2.67 GHz
    8GB memory
    Windows 7 64bit
    Please use plain text.
    Mentor
    rhasell
    Posts: 194
    Registered: ‎05-23-2007

    Re: Part Quantities

    01-21-2013 03:13 PM in reply to: cwhetten

    Very cool, thanks.

     

    I have run it briefly and will definately store it for later use. Does what you said it would, I will probably add some some code from other snippets to step through the Sub-assemblies as well, if I get it right I will post the update.

     

    With a bit of modification this snippet has lots of other uses as well.

     

    Regards
    Reg

    Autodesk Product Design Suite Premium 2013 sp1.1 (1)
    Intel Core i7 (950@3.07GHz)
    Windows 7x64 (Home)
    12GB Ram
    Nvidia GeForce GTX 560 Ti (1Gig - Ver:314.07)
    Please use plain text.
    *Expert Elite*
    Posts: 727
    Registered: ‎09-03-2008

    Re: Part Quantities

    01-21-2013 03:39 PM in reply to: rhasell

    I also thought about going through sub-assemblies.  But, you might not always want to do that.  If some of your sub-assemblies have drawings of their own, then you would want its sub-components to have quantities from the sub-assembly, not the higher assembly, right?

     

    Then again, if some of your sub-assemblies are phantom, then you would definitely want the rule to run through them and set the quantities of the sub-components from the highter assembly.

     

    It's kinda tricky.

     

    -cwhetten

    Please use plain text.