- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Solved! Go to Solution.