Export Parts List as Shown in Drawing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I've been dabbling in VB.Net to export a parts list from an AutoCAD Mechanical drawing to an Excel sheet, and it has been successfully exporting. However, my problem I've been running into is that what the list looks like in the export is variable to what the drawing displays. There's sometimes extra columns (some I can easily check for and delete, but others I can't anticipate like an extra part column from previous revisions), and sometimes the columns aren't in the right order. Normally I could just give an array of the column headers and order them accordingly, but some drawings have more or less columns than others. So, to put it simply, I'm wondering if there is a way to programmatically export the parts list as it shows in the drawing and not get all the excess data?
I've posted the class I have been using below to do this. Any help you could provide would be appreciated!
'Contains the AutoCAD Type Library
Imports Autodesk.AutoCAD.Interop
'Contains the AutoCAD/ObjectDBX Type Library
Imports Autodesk.AutoCAD.Interop.Common
Imports Autodesk.AutoCAD.ApplicationServices
Imports SymBBAuto
Public Class ExportParts
Dim FullPathName As String = "C:\Users\nicholas.biggs\Documents\VBNet_test.csv"
Dim BomName As String = "MAIN"
Dim acadApp As AcadApplication = Application.AcadApplication
Dim acadDoc As AcadDocument = acadApp.ActiveDocument
<Autodesk.AutoCAD.Runtime.CommandMethod("GetTheParts")> _
Public Sub GetTheParts()
'Code adapted from: https://forums.autodesk.com/t5/net/autocad-mechanical-automatic-parts-list-extraction-c/td-p/6374100
' by shaffer_nathan.
' --------------------------------------------------------------
' Get the Surface Texture Library Object
Try
' Get Interface to SymbolBBMMgr
Dim I_symBBmgr3 As IMcadSymbolBBMgr3 = Nothing
I_symBBmgr3 = acadDoc.Application.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr")
' Get Interface to BOMMgr from the active document
Dim I_cadBOMmgr3 As SymBBAuto.IMcadBOMMgr3 = Nothing
I_cadBOMmgr3 = I_symBBmgr3.BOMMgr(acadDoc)
' Save the Contents to Non-Interface variable
Dim cadBOMmgr As SymBBAuto.McadBOMMgr = Nothing
cadBOMmgr = I_cadBOMmgr3
' Dispose of the Interfaces
I_symBBmgr3 = Nothing
I_cadBOMmgr3 = Nothing
' Check if BOMName exists in Table
If cadBOMmgr.BOMTableExists(BomName) Then
' Get the BOMTable by name (Non-Interface Variable)
Dim cadBom As SymBBAuto.McadBOM = Nothing
cadBom = cadBOMmgr.GetBOMTableByName(BomName)
If cadBom IsNot Nothing Then
'Idea for sorting export: http://adndevblog.typepad.com/manufacturing/autocad-mechanical/
'Dim item As SymBBAuto.McadBOMItem
For Each item As SymBBAuto.McadBOMItem In cadBom.Items
Dim p As Long : p = Val(item.ItemNumber)
If p > 0 Then item.SortPriority = p
Next
cadBom.applySort()
cadBOMmgr.ExportBOM2(SymBBAuto.McadBOMExportFormatType.exCSV, cadBom, FullPathName, "Main", True)
End If
End If
Catch acEx As Autodesk.AutoCAD.Runtime.Exception
' Write Error Message
MsgBox(acEx.Message)
Catch ex As System.Exception
' Write Error Message
MsgBox(ex.Message)
End Try
End Sub
End Class
Thanks,
Nic Biggs