Monday, March 17, 2014

An iProp for the unique items

A request came in for a modification on the 'iProp For Everyone' post.  The post requested for the code to ignore additional instances of an occurrence.

One way of doing this is by using the AllReferencedDocuments.  There is only reference per file so this approach will take care of the unique item issue.  This differs from the original alternative approach I took where I looked at the ComponentOccurrences.

'   Get the active assembly. 
    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisApplication.ActiveDocument
    
'   Get the PropertySets object. 
    Dim oPropSets As PropertySets 
    Dim oPropSet As PropertySet 
    
'   Iterate thru each referenced document
    Dim oDoc As Document 
    For Each oDoc In oAsmDoc.AllReferencedDocuments 
        oPropSets = oDoc.PropertySets
        oPropSet = oPropSets.Item("Inventor User Defined Properties")     

        Try                                                
        '    Push the required iProperties down to the documents
            oSONumiProp = oPropSet.Item("SO_Number")
            oSONumiProp.Value = Sales_Order_Number
            oCompanyiProp = oPropSet.Item("Company")
            oCompanyiProp.Value = Customer_Name
            oProjectiProp = oPropSet.Item("Project Description")
            oProjectiProp.Value = Project_Description
        Catch
        '    Do not raise or display an error.
        End Try
    Next 


Hopefully you see some benefit in the above solution.  Leave me a comment and let me know.

Randy

"The mind is everything. What you think you become." - Buddha

2 comments:

  1. I'd like to use this to read the part level Thickness parameter and with that write to the stock number iProperty. How would I do that?

    ReplyDelete
  2. Hi Stephen,

    This can be done. You'd need to go thru the ComponentDefinition of the oDoc to get to the parameters.

    By the way, we moved all our blogging to our official company site:
    http://blogs.rand.com/manufacturing/

    Regards,
    Randy

    ReplyDelete