Inventor Drawing: Export Drawing BOM to Excel Template iLogic Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey guys I have been reading the forums for a solution to a iLogic program i want to make for a while and cannot seem to fin one.
For my situation, I have a large drawing set with a BOM parts list of the top assembly always on sheet 1. I want to be able to run an iLogic rule in my drawing to export that BOM to an Excel template my firm uses. I want to paste this data in the second tab of the Excel sheet. (this template has some Excel marcos, it would be cool if i could run them from the iLogic rule too, IDK if that is possible). Below is my code so far. The last line where it does the final export gives me an error below:
"_SaveAs method of Workbook class failed"
I have created this code by using other's code as a starting point. Any help is greatly appreciated.
'-------------Start of ilogic ------------------------------------------------ 'get the path and name of the drawing file path_and_name = ThisDoc.PathAndFileName(False) ' without extension 'define oDoc oDoc = ThisDoc.Document 'specify the drawing sheet 'oSheet = oDoc.Sheets("Sheet:1") ' sheet by name oSheet = oDoc.Sheets(1) ' first sheet ' say there is a Partslist on the sheet. oPartslist = oSheet.PartsLists(1) 'get Excel target folder path oFolder = Left(oPath, InStrRev(oPath, "U:\")) & "U:\" ' create a new NameValueMap object oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'specify an existing template file 'to use For formatting colors, fonts, etc oOptions.Value("EXCEL TEMPLATE Bill of Materials.xlsx") = "U:\Documents\EXCEL TEMPLATE Bill of Materials.xlsx" 'specify the columns to export oOptions.Value("ExportedColumns") = "ITEM;PART NUMBER;DESCRIPTION;LENGTH;WIDTH;QTY;STOCK;DXF FILENAME" 'specify the start cell oOptions.Value("StartingCell") = "A7" 'specify the XLS tab name 'here the file name is used oOptions.Value("PRINT BOM") = ThisDoc.FileName(True) 'without extension 'choose to include the parts list title row 'in this example "Ye Old List of Parts" is written to the StartingCell oOptions.Value("IncludeTitle") = False 'choose to autofit the column width in the xls file oOptions.Value("AutoFitColumnWidth") = False oPartslist.Export(oFolder & "\" & ".xlsx", _ PartsListFileFormatEnum.kMicrosoftExcel, oOptions) '-------------End of ilogic ------------------------------------------------