Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to export to Excel the parts list of all DWG files in a folder. Typically the first parts list in the first sheet is sufficient for my needs. I used this code from here https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-and-export-parts-list-in-a-id... but can't get it to work properly for all the files in the folder.
I wish to iterate through all the DWG files in the folder, open the DWG file, export the Parts List and close the file. Where am I messing up here?
Many thanks!
Public Sub Main() Dim wFolder As String = "C:\Inventor\test" Dim FileLocation As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(wFolder) Dim fi As System.IO.FileInfo() = FileLocation.GetFiles() For Each oFile As System.IO.FileInfo In fi 'Get only DWG files - Not PDFs or other files DwgFile = Left(oFile.FullName, Len(oFile.FullName) -3) & "dwg" ThisApplication.Documents.Open(DwgFile, True) ExportPartsList Next End Sub Public Sub ExportPartsList Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument Dim oSheets As Sheets = oDoc.Sheets 'get the path and name of the drawing file Dim fileName = ThisDoc.PathAndFileName(False) & ".xlsx" If (IO.File.Exists(fileName)) Then 'delete so as to overwrite IO.File.Delete(fileName) End If Dim oParents, otitles As New ArrayList Dim startRow = 1 Dim includeTitle = False Dim PartsListNumber = 1 Dim oPartslist As PartsList For Each sheet As Sheet In oSheets 'Find every sheet in the drawing For Each oPartslist In Sheet.PartsLists 'Find every partslist on the sheet If Not oParents.Contains(oPartslist.ReferencedDocumentDescriptor.FullDocumentName) Then oParents.Add(oPartslist.ReferencedDocumentDescriptor.FullDocumentName) ThisApplication.StatusBarText = "Exporting Sheet " & Sheet.Name & " of " & oSheets.Count & " Please Wait!" ' create a new NameValueMap object Dim oOptions = ThisApplication.TransientObjects.CreateNameValueMap 'specify the start cell oOptions.Value("StartingCell") = "A" & startRow 'specify the XLS tab name. Here the file name is used If Not otitles.Contains(oPartslist.Title) Then otitles.Add(oPartslist.Title) oOptions.Value("TableName") = oPartslist.Title Else oOptions.Value("TableName") = oPartslist.Title & PartsListNumber End If '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") = True ' export the Partslist to Excel with options oPartslist.Export(fileName, PartsListFileFormatEnum.kMicrosoftExcel, oOptions) PartsListNumber = PartsListNumber + 1 Else Logger.Info(Sheet.Name & ": there is already a partslist exported for file reference " & oPartslist.ReferencedDocumentDescriptor.FullDocumentName) End If Next Next oDoc.Close(True) End Sub
Solved! Go to Solution.