Public Sub WriteAssemblyStructure() ' Check that an assembly is open. Dim asmDoc As AssemblyDocument Dim docType As DocumentTypeEnum docType = ThisApplication.ActiveDocumentType If docType <> kAssemblyDocumentObject Then MsgBox "An assembly must be active." Exit Sub Else Set asmDoc = ThisApplication.ActiveDocument End If ' Get the name of the file to create. Dim csvFilename As String Dim saveDialog As FileDialog Call ThisApplication.CreateFileDialog(saveDialog) With saveDialog .Filter = "CSV (Command delimited)(*.csv)|*.csv" .DialogTitle = "Specify output filename" .OptionsEnabled = False .SuppressResolutionWarnings = True .ShowSave If .FileName = "" Then Exit Sub Else csvFilename = .FileName End If End With ' Open the file. Dim FilePointer As Integer FilePointer = FreeFile Open csvFilename For Output As #FilePointer ' Write the top-level assembly name. Print #FilePointer, asmDoc.DisplayName & "," & _ asmDoc.FullFileName ' Read through the assembly and write the structure out. Call WriteStructure(asmDoc.ComponentDefinition.occurrences, _ 1, FilePointer) ' Close the file. Close #FilePointer MsgBox "Completed writing assembly structure to: " & csvFilename End Sub Private Sub WriteStructure( _ ByVal occurrences As ComponentOccurrences, _ ByVal Level As Integer, _ ByVal FilePointer As Integer) ' Iterate through the occurrences in the current level. Dim occ As ComponentOccurrence For Each occ In occurrences ' Write information for this occurrence to the file. Print #FilePointer, String$(Level, ",") & _ occ.Name & "," & occ.Definition.Document.FullFileName ' If this occurrence is a subassembly iterate ' over its occurrences. If occ.DefinitionDocumentType = kAssemblyDocumentObject Then Call WriteStructure(occ.SubOccurrences, Level + 1, _ FilePointer) End If Next End Sub