I have a main assembly that have sub-assemblies (Level 1). The sub-assemblies in turn have parts+sub-assemblies (Level-2). I want the exported excel BOM to have parts+subassemblies (Level-2). I am using the following code to export to excel. But the problem is, when 'oBOM.StructuredViewFirstLevelOnly = False', all the part that are under sub-assembly 2 are also exported. I thought of traversing through the main assembly and not exporting the subassemblies (Level-2), but the BOMExport API erases the previous data when it is called each time.
So is there anyway we can set 'oBOM.StructuredViewFirstLevelOnly =' False only till first level and then true at the second level? Thank you.
Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument ' a reference to the BOM Dim oBOM As BOM oBOM = oDoc.ComponentDefinition.BOM ' the structured view to 'all levels' oBOM.StructuredViewFirstLevelOnly = False '(Want this to be false for level 1 and true for level 2) ' Make sure that the structured view is enabled. oBOM.StructuredViewEnabled = True ' a reference to the "Structured" BOMView Dim oStructuredBOMView As BOMView oStructuredBOMView = oBOM.BOMViews.Item("Structured") ' Export the BOM view to an Excel file oStructuredBOMView.Export ("C:\........", kMicrosoftExcelFormat)
you can travel through the assembly and give the exported excel a different name and the later combine the excel files. Here an example iLogic rule that will create a excel file for the level-1 assembly and different files for the level-2 assemblies.
Sub Main() Dim doc As AssemblyDocument = ThisDoc.Document 'export level-1 exportBom(doc, True) 'find all level-2 documents For Each occ As ComponentOccurrence In doc.ComponentDefinition.Occurrences 'next line will fail if an occurence is not an Document. (like a viritual part) Dim occDoc As Document = occ.ReferencedDocumentDescriptor.ReferencedDocument 'export level-2 assemblys If (occDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject) Then exportBom(occDoc, False) End If Next End Sub Public Sub exportBom(doc As AssemblyDocument, StructuredViewFirstLevelOnly As Boolean) ' a reference to the BOM Dim oBOM As BOM = doc.ComponentDefinition.BOM ' the structured view to 'all levels' oBOM.StructuredViewFirstLevelOnly = StructuredViewFirstLevelOnly ' Make sure that the structured view is enabled. oBOM.StructuredViewEnabled = True ' a reference to the "Structured" BOMView Dim oStructuredBOMView As BOMView = oBOM.BOMViews.Item("Structured") Dim excelFileName As String = doc.FullFileName.Replace(".iam", ".xls") ' Export the BOM view to an Excel file oStructuredBOMView.Export(excelFileName, FileFormatEnum.kMicrosoftExcelFormat) MsgBox("Create/exported file: " & excelFileName) End Sub
(i did not include code to combine the excel files)
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Can't find what you're looking for? Ask the community or share your knowledge.