Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

iLogic BOM Export - Export BOM of All Referenced Documents

e_frissell
Advocate

iLogic BOM Export - Export BOM of All Referenced Documents

e_frissell
Advocate
Advocate

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")

 

 

0 Likes
Reply
461 Views
2 Replies
Replies (2)

WCrihfield
Mentor
Mentor

Hi @e_frissell.  This similar ability has been asked for before.  I believe the main problem with that process was that when exporting another BOM to the same file you have already exported a BOM to, it wants to overwrite the existing sheet every time, instead of adding another sheet.  I'm pretty sure we found a workaround process for this problematic behavior though, I just can't remember which forum post  (or multiple forum posts) this was figured out at.  It seems to me like they had to manipulate the already existing Excel file somehow by code between exports.  Or they may have simply created another new Excel file with the new export process, then copied the new sheet from that file to the other existing Excel file after the export process.

Edit:  Here is a link to one of those posts:

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-code-to-export-bom-to-excel-f... 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

e_frissell
Advocate
Advocate

Thanks @WCrihfield - I ended up finding the issue in my code above - the part where the code named the Excel Files used ThisDoc.FullFileName and turns out that was always the top level assembly, since that's where the code ran.  Swapped that out for the display name of the reference document and removed the extension and now all the files appear.  Not perfect, but it's working

0 Likes