BOM.Export failes from VB.net

BOM.Export failes from VB.net

J_Dumont
Advocate Advocate
514 Views
3 Replies
Message 1 of 4

BOM.Export failes from VB.net

J_Dumont
Advocate
Advocate

I am having some difficulties exporting a BOM from VB.Net. I had the code working in iLogic but now I'm porting over to .Net in preparation for an Addin.

 

Here's my code below. The program seems to work fine and then errors at the end when exporting.

The folder I'm writing to has no restrictions and as I said, I can export from logic to the same directory without issue.

 

Public Sub BOMExport()
Dim openDoc As Document
openDoc = invApp.ActiveDocument
'Dim docFile As Document

'Get Folder and File name of Assembly
Dim oAsmFolderName As String = System.IO.Path.GetDirectoryName(openDoc.FullFileName) 'Get assembly folder name
Dim oAsmFileName As String = System.IO.Path.GetFileNameWithoutExtension(openDoc.FullFileName) 'Get assembly file name w/o extension

'Activate the Master LOD
Dim oACDef As AssemblyComponentDefinition
oACDef = openDoc.ComponentDefinition
oACDef.RepresentationsManager.LevelOfDetailRepresentations("Master").Activate()

'set a reference to the BOM
Dim oBOM As BOM
oBOM = openDoc.ComponentDefinition.BOM

Dim filename As String 'assume the file exists
filename = "C:\Test\BOM_Template.xml"
Call oBOM.ImportBOMCustomization(filename)

'set the folder to save to
Dim sFolder As String
sFolder = oAsmFolderName & "\" & oAsmFileName & " PDF Files"

'check for the folder and create it if it does not exist
If Not System.IO.Directory.Exists(sFolder) Then
System.IO.Directory.CreateDirectory(sFolder)
End If

'make sure that the Structured view is enabled.
oBOM.StructuredViewEnabled = True

'set the structured view to 'all levels'
oBOM.StructuredViewFirstLevelOnly = False

'set a reference to the "Structured" BOMView
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Structured")

'export the BOM
oBOMView.Export(PDFFolderName & "\" & oAsmFileName & ".xlsx", FileFormatEnum.kMicrosoftExcelFormat) 'kMicrosoftExcelFormat)


End Sub

0 Likes
Accepted solutions (1)
515 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

is your invApp declared?

Public Sub BOMExport()
Dim openDoc As Document
openDoc = invApp.ActiveDocument

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 4

_dscholtes_
Advocate
Advocate
Accepted solution

Maybe it's just me, but...

 

<cut>

Dim sFolder As String
sFolder = oAsmFolderName & "\" & oAsmFileName & " PDF Files"

<cut>

'export the BOM
oBOMView.Export(PDFFolderName & "\" & oAsmFileName & ".xlsx", FileFormatEnum.kMicrosoftExcelFormat) 'kMicrosoftExcelFormat)

 

don't the folder names mismatch (sFolder vs PDFFolderName)?

0 Likes
Message 4 of 4

J_Dumont
Advocate
Advocate

Nice catch. You are correct with the variable names. However, the variable PDFFolderName is Public and I forgot to remove the sFolder. The weird thing I only used sFolder to check for the folder and create it if null.

I switched everything to PDFFolderName is the export is working.

 

Nothing good comes from programming late int the night. I just noticed I misspelled fails in my description, sorry.

 

Thanks for the assist!!!

0 Likes