Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export Parts list to .csv: Sheet error.

1 REPLY 1
Reply
Message 1 of 2
D_Beezhold
618 Views, 1 Reply

Export Parts list to .csv: Sheet error.

First off: Inventor Professional 2012

 

Second, like many companies we export our parts lists (in our case, .csv) for our MRP system. I borrowed and modified Curtis' ilogic code that I found in previous posts on these forums to fit our needs. The only thing I'm getting hung up on is the sheet in which the parts list is found.

 

Right now the code is pointing only to sheet 1 to find the parts list. Unfortunately some of our assembly drawings have many sheets and the parts list can be on any of them. So whenever I run the rule in a drawing that doesn't have the parts list on sheet 1 I get an error. Is there some way for Inventor to search all the sheets? or at the least search on the active sheet?

 

This is what I have so far. Any and all help is appriciated.

 

'name for .csv file
name = iProperties.Value("Project", "Part Number")

'path for .csv file
folderName = "L:\CadLink\"

Dim oDoc As Inventor.DrawingDocument
oDoc = ThisDoc.Document

Dim oSheet As Inventor.Sheet
'oSheet = oDoc.Sheets(1) ' first sheet
oSheet = oDoc.Sheets("Sheet:1") ' sheet by name

' say there is a Partslist on the sheet.
Dim oPartslist As PartsList
oPartslist = oSheet.PartsLists(1)

' create a new NameValueMap object
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'specify the columns to export
oOptions.Value("ExportedColumns") = "IT.;QTY;PART NO."

'specify the start cell
oOptions.Value("StartingCell") = "A1"

'specify the XLS tab name
'
here the file name is used
oOptions.Value("TableName") = ThisDoc.FileName(False) 'without extension

'choose to include the parts list title row
oOptions.Value("IncludeTitle") = False

'choose to autofit the column width in the xls file
oOptions.Value("AutoFitColumnWidth") = False

'check for existing XLS file and delete it if found
If Dir(folderName & name & ".csv") <> "" Then
Kill (folderName & name & ".csv")
Else
End If

' export the Partslist to Excel.

' folderName = "C:\temp"
oPartslist.Export(folderName & name & ".csv", PartsListFileFormatEnum.ktextfilecommadelimited, oOptions)
1 REPLY 1
Message 2 of 2
adam.nagy
in reply to: D_Beezhold

Hi,

 

Try replacing this:

Dim oSheet As Inventor.Sheet
'oSheet = oDoc.Sheets(1) ' first sheet
oSheet = oDoc.Sheets("Sheet:1") ' sheet by name

With this:

Dim oSheet As Inventor.Sheet
For Each oSheet In oDoc.Sheets
	If oSheet.PartsLists.Count > 0 Then Exit For
Next

I hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report