Export parts list as .csv to specific folder.

Export parts list as .csv to specific folder.

jostroopers
Collaborator Collaborator
1,025 Views
2 Replies
Message 1 of 3

Export parts list as .csv to specific folder.

jostroopers
Collaborator
Collaborator

Hi.

I want to export my parts list to a .csv file and that is working.

But i want to save the .csv file to the folder: Z:\Uni_Link\Import\CSV

I have tried this with this code but I cannot get it done.
The .csv file is now always saved in the folder that also contains the .dwg in which the parts list was created.

 

Dim oDoc As Inventor.DrawingDocument
oDoc = ThisDoc.Document
path_and_name = ThisDoc.PathAndFileName(False)' without extension

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)

''set the folder to save to
'Dim sFolder As String
'sFolder = Left(sPath, InStrRev(sPath, "\")) & "Z:\Uni_Link\Import\CSV"

''check for the folder and create it if it does not exist
'If Not System.IO.Directory.Exists(sFolder) Then
'System.IO.Directory.CreateDirectory(sFolder)
'End If

' export the Partslist to Excel.
oPartslist.Export(path_and_name & ".csv", PartsListFileFormatEnum.kTextFileCommaDelimited, oOptions) 
Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes
Accepted solutions (1)
1,026 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Try this:

(I'm also showing how to specify the options, but have that portion commented out, due to how custom those setting are.)

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oFileName As String = IO.Path.GetFileNameWithoutExtension(oDDoc.FullFileName)
Dim oPath As String = "Z:\Uni_Link\Import\CSV\"
Dim oNewFullName = oPath & oFileName & ".csv"
Dim oPartslist As PartsList = oDDoc.Sheets.Item("Sheet:1").PartsLists.Item(1)
If Not IO.Directory.Exists(oPath) Then
	IO.Directory.CreateDirectory(oPath)
End If
If IO.File.Exists(oNewFullName) Then
	oAns = MsgBox("That file already exists. Do you want to overwrite it?", vbYesNo + vbQuestion, " ")
	If oAns = vbNo Then Exit Sub
End If
oPartslist.Export(oNewFullName, PartsListFileFormatEnum.kTextFileCommaDelimited)

'Dim oOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
'oOptions.Add("TableName", "Parts List for " & oFileName)
'oOptions.Add("ExportedColumns", "Column 1;Column 2;Column 3;Column 4;Column 5")
'oOptions.Add("IncludeTitle",True)
'oOptions.Add("StartingCell", "A1")
'oOptions.Add("Template", "C:\Temp\CSV Parts List Template.csv")
'oOptions.Add("AutoFitColumnWidth",True)
'oPartslist.Export(oNewFullName, PartsListFileFormatEnum.kTextFileCommaDelimited, oOptions)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

jostroopers
Collaborator
Collaborator

@WCrihfield  thanks.

Great, this is exactly what I needed.
I am not yet using the options.
Will see if it helps me at a later stage.

Thank you very much again.
And keep giving this support, this  helps us further to make great designs.

 

Mvg Jos
Youre drawings are as good as the symbols that compleet them.....
0 Likes