iLogic BOM Export - Export BOM of All Referenced Documents
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey guys, running into a bit of a headache trying to set up an export of a top level assembly that ALSO exports all the sub-assembly BOM's as well. Found one of Clint's iLogic scripts and have been modifying it to fit my need however in a bit of bind. Idea is that it exports the first level of the top level BOM, then iterates through all referenced documents and if that referenced document is an assembly exports the first level BOM of that assembly.
A really cool alternative would be for the Epicor Export instead of creating individual files it would add a sheet every time a new refDoc/refBom was found and add the BOM to the new sheet : )
Any help would be appreciated
' https://clintbrown.co.uk/2019/09/21/bom-export-with-ilogic/
'Adapted from Inventor API Samples by Clint Brown
'iLogic code Originally posted at https://clintbrown.co.uk/bom-export-with-ilogic
oDoc = ThisDoc.ModelDocument
'Ensure that we are in an Assembly file - Exit if not
If oDoc.DocumentType = kPartDocumentObject Then
MessageBox.Show("You need to be in an Assembly to Export a BOM", "@ClintBrown3D iLogic")
Return
End If
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
Dim projectNumber As String = Left(oDoc.DisplayName, 4)
Dim pathMod As String = ""
Dim oPath As String = System.Environment.GetFolderPath(Desktop) & "\Export BOMs\" & projectNumber & "\"
If Not System.IO.Directory.Exists(oPath) Then
System.IO.Directory.CreateDirectory(oPath)
End If
Dim refDoc As Document
'**************************************************************************************
'You can change the output path by editing CSVpath below - by default the path is the same as the assembly file
'CSVpath = ("C:\Inventor\") 'If you change the path, remember to keep a \ at the end
CSVpath = oPath
'**************************************************************************************
'Get user input for Export Type:
Dim MyArrayList As New ArrayList
MyArrayList.Add("")
MyArrayList.Add("Export BOM for Epicor")
MyArrayList.Add("")
MyArrayList.Add("Export Structured BOM")
MyArrayList.Add("")
MyArrayList.Add("Parts Only - (Shows components in a flat list)")
ClintsBoMExporter = InputListBox("Choose a BoM type to Export: " & ClintBrown3D , MyArrayList, d0, Title := "@ClintBrown3D: BoM Export ", ListName := "BoM Type")
If ClintsBoMExporter = "Export BOM for Epicor" Then :GoTo GoEpicorExport : End If
If ClintsBoMExporter = "Export Structured BOM" Then :GoTo GoAllLevelsExport : End If
If ClintsBoMExporter = "Parts Only - (Shows components in a flat list)" Then : GoTo GoPartExport : End If
If ClintsBoMExporter = "" Then : Return : End If
'STRUCTURED BoM ALL LEVELS:
GoAllLevelsExport:
' the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False
' Make sure that the structured view is enabled.
oBOM.StructuredViewEnabled = True
Dim oStructuredBOMView As BOMView
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
' Export the BOM view to an Excel file
oStructuredBOMView.Export(CSVpath + pathMod + ThisDoc.FileName(False) + "-Export"+ ".xls", kMicrosoftExcelFormat)
GoTo GoLaunch:
'STRUCTURED BoM for Epicor
GoEpicorExport :
oBOM.StructuredViewFirstLevelOnly = True
oBOM.StructuredViewEnabled = True
oStructuredBOMView = oBOM.BOMViews.Item("Structured")
oStructuredBOMView.Export(CSVpath + ThisDoc.FileName(False) + "-Epicor" + ".xls", kMicrosoftExcelFormat)
Dim refBom As BOM
For Each refDoc In oDoc.AllReferencedDocuments
If refDoc.DocumentType = kassemblydocumentobject Then
' not sure about the parts below
refBom = refDoc.ComponentDefinition.BOM
refBom.StructuredViewFirstLevelOnly = True
refBom.StructuredViewEnabled = True
oStructuredBOMView = refBom.BOMViews.Item("Structured")
oStructuredBOMView.Export(CSVpath + ThisDoc.FileName(False) + "-Epicor" + ".xls", kMicrosoftExcelFormat)
End If
Next
GoTo Golaunch:
'PARTS ONLY BoM
GoPartExport:
oBOM.PartsOnlyViewEnabled = True
Dim oPartsOnlyBOMView As BOMView
oPartsOnlyBOMView = oBOM.BOMViews.Item("Parts Only")
MsgBox(CSVpath + ThisDoc.FileName(False) + ".xls")
oPartsOnlyBOMView.Export (CSVpath + ThisDoc.FileName(False) +"-Parts" + ".xls", kMicrosoftExcelFormat)
GoTo GoLaunch:
'Get user input - do you want to see the BoM?
GoLaunch:
'i = MessageBox.Show("Preview the BOM?", "@ClintBrown3D iLogic", MessageBoxButtons.YesNo)
'If i = vbYes Then : launchviewer = 1 : Else : launchviewer = 0 : End If
launchviewer = 0
If launchviewer = 1 Then ThisDoc.Launch(CSVpath + ThisDoc.FileName(False) + ".xls")