Export parts list not working

Export parts list not working

jostroopers
Collaborator Collaborator
1,004 Views
6 Replies
Message 1 of 7

Export parts list not working

jostroopers
Collaborator
Collaborator

I have the link below explaining how to export a parts list to excel.
https://clintbrown.co.uk/2020/07/18/export-formatted-parts-list-with-ilogic/
I have placed all files in the correct folder C: \ TEMP.
I have placed the code in my assy and have not changed anything.
When I run the code from the assy I don't get an error.
The folder Parts Lists is created.
The Template-Export Parts List.dwg does not open.
No parts list is placed temporarily either.
Nothing else happens and the assy is closed.
I hope someone has an idea what I am doing wrong or am I missing something.
I may have to change something in the code.
What I do wonder is how the code knows which parts list to use.
According to the explanation, the parts list called 'Unofficial' should be used.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
1,005 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hi jostroopers

 

What version of Inventor are you running? The code only works with Inventor 2021, as the template drawing is set up in 2021 format.

 

If you are using 2021, make sure that you "unblock" the files before running the code.

 

Hope this helps

 

 

0 Likes
Message 3 of 7

jostroopers
Collaborator
Collaborator

Hi @Anonymous 

Thanks for youre reaction.

I work with Inventor 2021.

And no, i didn't unlock the zip file.

But after i first unlock the zip file and placed them in the TEMP folder its still not working.

Its only makes the folder Parts List and nothing is placed in there.

In Inventor i get the MsgBox("We've encountered a mystery") and the assy close.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 4 of 7

Anonymous
Not applicable

I've just tested this on my system. It works on most assemblies, have you tried this on any other assemblies?

 

I do have one assembly that seems to behave as you explain.

 

It seems that if there are any issues in the file, that the Parts list code will not run as expected. In my example, if I go to "Manage", then "Rebuild All", there are issues with mates.

 

@ClintBrown3D Autodesk Inventor 184.png

 

Once these are tidied up, everything works as expected.

0 Likes
Message 5 of 7

jostroopers
Collaborator
Collaborator

 

My first assy had no issues.

But i took another simple assy with no issues.
I manually placed a parts list in the template, Template-Export Parts List.dwg.
I found out that I couldn't post the parts list because the BOM view was disabled. After I had adjusted that in the assy I was able to place the parts list. Then I ran the code again but it didn't work yet.

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Message 6 of 7

M.Hawryluk
Advocate
Advocate

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.

 

 

 

0 Likes
Message 7 of 7

bradeneuropeArthur
Mentor
Mentor

Maybe you have a permission issue on c: or the temp folder should not be TEMP but Temp

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