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: 

Exporting Parts List from idw file using VB.net?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
mucip
9102 Views, 5 Replies

Exporting Parts List from idw file using VB.net?

Hi,

I'm using VB.NET and Inventor 2010. I want to export parts list from idw file to xls or csv file. I checked the internet but could not find trace only exporting BOM from IAM...

 

I can open inventor and open idw file in VB.net. But could not reach to Parts List.. I checked Inventor2010ObjectModel and sawDrawingdocument>DrawingBOM but could not get success..

 

Regards,

Mucip:)

5 REPLIES 5
Message 2 of 6
YuhanZhang
in reply to: mucip

Hi Mucip,

 

Can you paste a snippet of your code for accessing the Partslist?

And below is a sample code for how to access a Partslist, hope it helps:

 

Sub ExportPartslist()
    ' say there is a drawing document opened
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.Sheets(1)
    
    ' say there is a Partslist on first sheet.
    Dim oPartslist As PartsList
    Set oPartslist = oSheet.PartsLists(1)
    
    ' export the Partslist to excel.
    oPartslist.Export "C:\Partslist.xls", kMicrosoftExcel

End Sub

 

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 3 of 6
mucip
in reply to: YuhanZhang

Dear Rocky ZHANG,

You're perfect 🙂

My code is below. May be someone who has same problem wants to read it in the future...

 

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Dim inventorApp As Inventor.Application
      
        ' Attempt to get a reference to a running instance of Inventor.
        Try
            inventorApp = GetObject(, "Inventor.Application")
            inventorApp.Documents.Open(TextBox1.Text, True)
        Catch ex As Exception
            'inventorApp = Nothing
            Try
                inventorApp = CreateObject("Inventor.Application")
                inventorApp.Visible = True
                inventorApp.Documents.Open(TextBox1.Text, True)
            Catch ex1 As Exception
                MsgBox("Error starting Inventor.")
                Exit Sub
            End Try
        End Try

      
        'starting export...
        Dim oDoc As Inventor.DrawingDocument
        oDoc = inventorApp.ActiveDocument

        Dim oSheet As Inventor.Sheet
        oSheet = oDoc.Sheets(1)

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

        ' export the Partslist to excel.
        oPartslist.Export("C:\temp\Partslist.csv", PartsListFileFormatEnum.kTextFileTabDelimited)
        MsgBox("Transfer finished")
    End Sub

Message 4 of 6
Anonymous
in reply to: mucip


@mucip wrote:

Dear Rocky ZHANG,

You're perfect 🙂

My code is below. May be someone who has same problem wants to read it in the future...

 

        ' export the Partslist to excel.
        oPartslist.Export("C:\temp\Partslist.csv", PartsListFileFormatEnum.kTextFileTabDelimited)
        MsgBox("Transfer finished")
    End Sub


It seems as if your Export command is written incorrectly.

 

If your inention is to export to an Excel Spreadsheet using CSV format, change kTextFileTabDelimited to kMicrosoftExcel

 

I, myself spent hours on the same problem.  I wanted to export to Excel using the CSV format, rather than the Default Excel format.

 

By the way, I'm trying to export the file to a specific location: D:\Exported Part Lists using the same name as the current idw.  How do I do that?

 

Hope that helps!

Message 5 of 6
mucip
in reply to: Anonymous

By the way, I'm trying to export the file to a specific location: D:\Exported Part Lists using the same name as the current idw. How do I do that?

 

Hi,

You're already opening idw file from variable...

 

Try
            inventorApp = GetObject(, "Inventor.Application")
            inventorApp.Documents.Open(TextBox1.Text, True)
        Catch ex As Exception

 

Then you may get idw name from this variable and add end of variable ".csv" string...

 

Regards,

Mucip:)

Message 6 of 6
Anonymous
in reply to: mucip

Here is my complete code:

 

'get the path and name of the drawing file
path_and_name = ThisDoc.PathAndFileName(False) ' without extension
'path_and_name2 ="D:\Exported Parts List"
'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") = "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
'in this example "Ye Old List of Parts" is written to the StartingCell
oOptions.Value("IncludeTitle") = False         


'choose to autofit the column width in the xls file
oOptions.Value("AutoFitColumnWidth") = True
       
'check for existing XLS file and delete it if found
If Dir(path_and_name & ".csv") <> "" Then
Kill (path_and_name & ".csv")
Else
End If

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

MessageBox.Show("Inventor Parts List successfully Exported To Correct Location Using CSV Format!", "Export Results")

 

How do I get the file to export to D;\Exported Part Lists ?

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report