Hi @jostroopers
I've experienced exactly the same behavior today, but after a quick look into the code I noticed that the part responsible for creation of drawing, inserting view and starting Export rule is missing.
If you look into Clint's blog post you will see that both parts of the provided code are the same (obvious editiorial issue). So, I've carefully watched the “Explainer” video attached to the blog post and there it is 🙂
In order to export BOM, use the code shown below in an Assembly and follow all the instructions from the blog:
'Assembly File code from Clint Brown's blog video https://www.youtube.com/watch?v=OIX0jM0KmZY&t=2s
'Check if this is an Assembly File
UnofficialInventor = ThisApplication.ActiveDocument
If UnofficialInventor.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show ("This rule can only be run in an Assembly File => Exiting Rule", "Unofficial Inventor")
Return
End If
'This bit of code is adapted from sample by Mike Deck
'Originally posted here: https://forums.autodesk.com/t5/inventor-customization/ilogic-coding-to-create-automated-drawing/td-p/3331455
oPathForDWGTemplate = "C:\TEMP\Template - Export Parts List.dwg"
Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, oPathForDWGTemplate, True)
Dim oSheet As Sheet
Dim oTG As TransientGeometry
Dim oView1 As DrawingView
'In parts and assemblies - Write file name and path to temp text file
oWrite = System.IO.File.CreateText("C:\TEMP\part1.txt")
oWrite.WriteLine(ThisDoc.FileName(False))
oWrite.Close()
oAssyDoc = ThisDoc.Document
oSheet = oDrawingDoc.Sheets.Item(1)
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(10, 10)
oBaseView = oSheet.DrawingViews.AddBaseView(oAssyDoc, oPoint1, 1/100, kFrontViewOrientation, kHiddenLineDrawingViewStyle)
Call ThisApplication.CommandManager.ControlDefinitions.Item("iLogic.RegenAllRules").Execute 'This re-generates the "Export" Rule.
In the "Export" rule for template I had to add one extra line to pull out the "Unofficial" Part List style.
I did it because even if I purged all the styles except "Unofficial" it was not working properly in my case.
You can also see a small addition to the original code used for debugging (Trace.WriteLine trick found here: https://adndevblog.typepad.com/manufacturing/2014/08/debug-ilogic.html)
Imports System.Diagnostics ' Needed for trace messages
oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'Create a new NameValueMap object
'iLogic Utility by @ClintBrown3D originally posted here --> https://clintbrown.co.uk/export-formatted-parts-list-with-ilogic
'Parts list placement from Autodesk Inventor API samples
'Parts list export based on Curtis Waguespack's blog post --> https://inventortrenches.blogspot.com/2011/06/ilogic-export-parts-list-with-options.html
'XLS SETUP--------------------------------------------------------------XLS SETUP---------------------------------------------------------------------------XLS SETUP
oOptions.Value("Template") = "C:\Temp\PartListExport.xlsx" 'Specify an existing template file 'use it for formatting colors, fonts, etc
oExcelSaveLocation = "C:\Temp\Parts Lists\" 'Make sure path has "\" at end -> eg C:\Temp\Parts Lists\
'Create XLS Parts List folder
If (Not System.IO.Directory.Exists(oExcelSaveLocation)) Then
System.IO.Directory.CreateDirectory(oExcelSaveLocation)
End If
'specify the columns to export
oOptions.Value("ExportedColumns") = "ITEM;QTY;PART NUMBER;DESCRIPTION;MATERIAL;MASS" 'These Must match what is shown on the drawing!!!
'specify the start cell
oOptions.Value("StartingCell") = "A2"
'choose to include the parts list title row
oOptions.Value("IncludeTitle") = True
'choose to autofit the column width in the xls file
oOptions.Value("AutoFitColumnWidth") = True
'XLS SETUP--------------------------------------------------------------XLS SETUP---------------------------------------------------------------------------XLS SETUP
Dim oDrawDoc As DrawingDocument 'Set a reference to the drawing document.' This assumes a drawing document is active
oDrawDoc = ThisApplication.ActiveDocument
Dim oSheet As Sheet 'Set a reference to the active sheet.
oSheet = oDrawDoc.ActiveSheet
Dim oDrawingView As DrawingView 'Set a reference to the first drawing view on' the sheet. This assumes the first drawing' view on the sheet is not a draft view.
oDrawingView = oSheet.DrawingViews(1)
Dim oBorder As Border 'Set a reference to th sheet's border
oBorder = oSheet.Border
Dim oPlacementPoint As Point2d
If Not oBorder Is Nothing Then 'A border exists. The placement point' is the top-right corner of the border
oPlacementPoint = oBorder.RangeBox.MaxPoint
Else' There is no border. The placement point is the top-right corner of the sheet.
oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height)
End If
Dim oPartsList As PartsList 'Create the parts list.
oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint)
'Set parts list to a specific style
oPartsList.Style = oDrawDoc.StylesManager.PartsListStyles.Item("Unofficial")
Trace.WriteLine("Part List formatted successfully")
ThisDoc.Document.SaveAs("C:\Temp\DeleteMe2.dwg", False)
Trace.WriteLine("DWG saved")
oRead = System.IO.File.OpenText("C:\TEMP\part1.txt") 'Get Original Assembly file name
EntireFile1 = oRead.ReadLine()
oRead.Close()
oDrawingName = EntireFile1
Trace.WriteLine("Assembly name received")
oDoc = ThisDoc.Document 'Define oDoc
path_and_name = oExcelSaveLocation + oDrawingName
'Specify the drawing sheet
oSheet = oDoc.Sheets("Sheet:1") 'Select sheet by name
oPartsList = oSheet.PartsLists(1) 'Say there is a Partslist on the sheet.
If Dir(path_and_name & ".xlsx") <> "" Then
Kill(path_and_name & ".xlsx")
Else
End If 'Check for existing XLS file and delete it if found
'On Error GoTo ClintsErrorTrap
Trace.WriteLine("Prepared to export to Excel")
oPartsList.Export(path_and_name & ".xlsx", PartsListFileFormatEnum.kMicrosoftExcel, oOptions ) 'Export the Partslist to Excel with options
Trace.WriteLine("Exported to Excel")
ThisDoc.Launch(path_and_name & ".xlsx") 'Open Parts List
ThisDoc.Document.Close(True)
'Return
'ClintsErrorTrap :
'MsgBox("We've encountered a mystery")
'ThisDoc.Document.Close(True)
@Anonymous
Thank you so much for the effort you put into creation of Unofficial Inventor Blog!
It is pity you will no longer publish there.