Message 1 of 9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to export a structurend BOM-list from an assembly directly to Excel. Is this possible or must I first export the data to a drawing file?
I've been copying and pasting code and have come up with the following code. The last line doesn't seem to work. Exporting with the options is somehow not working. My iLogic knowledge is limited and any helpp would really be welcome.
Cheers Josh
SyntaxEditor Code Snippet
'check that the active document Is an assembly file If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then MessageBox.Show("Please run this rule from the assembly file.", "iLogic") Exit Sub End If Dim oAsmDoc As AssemblyDocument oAsmDoc = ThisApplication.ActiveDocument Dim oBOM As BOM oBOM = oAsmDoc.ComponentDefinition.BOM '''========================================================================================== '''You can change the output path by editing oPATH below oAsmName = Left(oAsmDoc.DisplayName, Len(oAsmDoc.DisplayName) - 4) oRevNum = iProperties.Value("Project", "Revision Number") oPath = ThisDoc.Path oFolder = oPath & "\" & oAsmName & "-Rev_" & oRevNum & "-PF" 'Check for the folder and create it if it does not exist If Not System.IO.Directory.Exists(oFolder) Then System.IO.Directory.CreateDirectory(oFolder) End If ''STRUCTURED BoM =========================================================================== '' 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") 'check For existing XLS file And delete it If found If Dir(oFolder & "\" & oAsmName & "-Rev_" & oRevNum & ".xls") <> "" Then Kill(oFolder & "\" & oAsmName & "-Rev_" & oRevNum & ".xls") End If ' create a new NameValueMap object oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'specify an existing template file to use For formatting colors, fonts, etc oOptions.Value("Template") = "F:\Hgn-SHUP\Technische bibliotheken\Inventor\01 SupportFiles\Inventor 2014\Templates\Template Partslist.xls" 'specify the columns to export oOptions.Value("ExportedColumns") = "ITEM;QTY;DESCRIPTION;PART NUMBER;MATERIAL" 'specify the start cell oOptions.Value("StartingCell") = "A5" 'specify the XLS tab name, I used the filename of the drawing oOptions.Value("TableName") = oAsmName & "-Rev_" & oRevNum 'without extension 'include the parts list title row oOptions.Value("IncludeTitle") = True 'autofit the column width in the xls file oOptions.Value("AutoFitColumnWidth") = True ' export the Partslist to Excel with above options oStructuredBOMView.Export(oFolder & "\" & oAsmName & "-Rev_" & oRevNum & ".xls", PartsListFileFormatEnum.kMicrosoftExcel, oOptions)
Solved! Go to Solution.