Export Parts List using iLogic - I've broken some code

Export Parts List using iLogic - I've broken some code

andrew_canfield
Collaborator Collaborator
1,129 Views
5 Replies
Message 1 of 6

Export Parts List using iLogic - I've broken some code

andrew_canfield
Collaborator
Collaborator

Hello

 

I used this 

http://inventortrenches.blogspot.com/2011/06/ilogic-export-parts-list-with-options.html

 

& it works on the default template but if I change the drawing style (for a custom parts list) it breaks.

What line here refers to the style in use for the parts list?

 

'-------------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)

     

' create a new NameValueMap object

oOptions = ThisApplication.TransientObjects.CreateNameValueMap

 

'specify an existing template file

'to use For formatting colors, fonts, etc

oOptions.Value("Template") = "C:\Temp\PartListExport.xls"

 

'specify the columns to export         

oOptions.Value("ExportedColumns") = "QTY;PART NUMBER;DESCRIPTION"

 

'specify the start cell

oOptions.Value("StartingCell") = "A3"

 

'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

'in this example "Ye Old List of Parts" is written to the StartingCell

oOptions.Value("IncludeTitle") = True          

 

'choose to autofit the column width in the xls file

oOptions.Value("AutoFitColumnWidth") = True

       

' export the Partslist to Excel with options

oPartslist.Export(path_and_name & ".xls", _

PartsListFileFormatEnum.kMicrosoftExcel, oOptions)  

 

'-------------End of ilogic ------------------------------------------------

0 Likes
Accepted solutions (2)
1,130 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor
Accepted solution

This line is specifying an excel template file to reference for style:

oOptions.Value("Template") = "C:\Temp\PartListExport.xls"

while this line is specifying the output file:

oPartslist.Export(path_and_name & ".xls", PartsListFileFormatEnum.kMicrosoftExcel, oOptions)

Is that what you were asking about?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 6

andrew_canfield
Collaborator
Collaborator

Thanks

Exporting the parts list from the template in use (not a test one) appears to have fixed the issue 🙂

 

0 Likes
Message 4 of 6

andrew_canfield
Collaborator
Collaborator

a snag..

this did export the parts list to the same folder as the .idw, I'm trying to change this destination to the users desktop (code copied from a different rule).

The file name appears to be different in the error message to the ilogic message box..

the file is called "Parts List c.xlsx" but the error calls the file "91B28100" (this name will change too).

path and name.JPGexcel warning.JPG

'define oDoc
oDoc = ThisDoc.Document


Dim oFolder As String = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) & "\Part List"
If Not System.IO.Directory.Exists(oFolder) Then 
    System.IO.Directory.CreateDirectory(oFolder)
End If



'get the path and name of the drawing file
'path_and_name = ThisDoc.PathAndFileName(False) ' without extension

Fname = ThisDoc.FileName(False) 'without extension

path1 = (System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) & "\Parts List")

path_and_name = path1 & "\" & Fname  & ".xlsx"



'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)
     
' create a new NameValueMap object
oOptions = ThisApplication.TransientObjects.CreateNameValueMap

'specify an existing template file
'to use For formatting colors, fonts, etc
'oOptions.Value("Template") = "C:\Temp\PartListExport.xls"

oOptions.Value("Template") = "K:\02 Inventor\JFNL\2018\01_Design Data\iLogic\UI\PL2018.xlsx"
 
 
'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 autofit the column width in the xls file
oOptions.Value("AutoFitColumnWidth") = True


MessageBox.Show(path_and_name, "path_and_name")
       
' export the Partslist to Excel with options
oPartslist.Export(path_and_name, PartsListFileFormatEnum.kMicrosoftExcel, oOptions)  

'MessageBox.Show(path_and_name, "path_and_name2")

 

Regards

 

Andrew

 

0 Likes
Message 5 of 6

andrew_canfield
Collaborator
Collaborator
Accepted solution

found a typo... Part List & Parts List..

0 Likes
Message 6 of 6

jonathan.victor
Advocate
Advocate

I'm usinge the same code, and its runnig perfectly, but how can i get rid of that confirmation to overwrite the table name when the template already has a sheet with the same name? 

jonathanvictor_0-1681310210171.png

 

0 Likes