In my last post, I showed one solution to a common task of using assembly level parameters to set iProperties of part files in your assembly using an Array and a For Next Loop. Using that solution, we specified each component that we wanted to push the iProperties to.
In this post, I'd like to discuss another solution that will push iProperties down to all components in your assembly, even those inside of sub-assemblies.
In this post, I'd like to discuss another solution that will push iProperties down to all components in your assembly, even those inside of sub-assemblies.
Sub Main Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument ' Call the function that does the recursion. Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1) End Sub Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, Level As Integer) ' Iterate through all of the occurrences in this assembly. Level 1 components. Dim oOcc As ComponentOccurrence For Each oOcc In Occurrences ' Get the selected item document occurrence name Dim oBrowserNode As String oBrowserNode = oOcc.Name Try ' Push the required iProperties down to the occurrences iProperties.Value(oBrowserNode, "Custom", "SO_Number") = Sales_Order_Number iProperties.Value(oBrowserNode, "Custom", "Company") = Customer_Name iProperties.Value(oBrowserNode, "Project", "Project") = Project_Description Catch ' Do not raise or display an error. End Try ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) End If Next End SubThe above code will go iterate through each occurrence in your assembly and set the required iProperties. If the occurrence is a sub-assembly, it will also iterate through each component inside of that sub-assembly.
Hopefully you see some benefit in the above solution. Leave me a comment and let me know.
Randy
Randy
"The only way to do great work is to love what you do." - Steve Jobs