How can I make a traverse assembly sub that I can reuse?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I have this code. It tends to work ok but I'm looking to improve the efficiency of the coding for future endeavors. I'm looking to take this method of traversing the assembly and create a sub that can be used over and over for all various traversing code I need to write. The problem I find is that I wind up needing 100 variables to cover all the situations and things I want to do. I'm hoping someone has a way of traversing an assembly without having to have all the rewrite code. I imagine this is something simple but I'm just not getting it.
Private Sub TraverseAssemblyPaint(Occurrences As ComponentOccurrences, Level As Integer) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim oOcc As ComponentOccurrence Dim ptdocCurrent As PartDocument Dim ptcdCurrent As PartComponentDefinition For Each oOcc In Occurrences ' Print the name of the current occurrence. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then ptcdCurrent = oOcc.Definition ptdocCurrent = ptcdCurrent.Document ptdocCurrent.ActiveRenderStyle = ptdocCurrent.RenderStyles.Item("Glossy - Gold") ptdocCurrent.Update() End If ' Check to see if this occurrence represents a subassembly ' and recursively call this function to traverse through it. If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then Call TraverseAssemblyPaint(oOcc.SubOccurrences, Level + 1) End If Next End Sub Private Sub PaintFile_Click(sender As Object, e As EventArgs) Handles PaintFile.Click ' Get the active assembly. Dim oAsmDoc As AssemblyDocument oAsmDoc = appApp.ActiveDocument 'Debug.Print(oAsmDoc.DisplayName) ' Call the function that does the recursion. Call TraverseAssemblyPaint(oAsmDoc.ComponentDefinition.Occurrences, 1) End Sub