Continue to Site

Welcome to 3DCADForums

Join our CAD community forums where over 25,000 users interact to solve day to day problems and share ideas. We encourage you to visit, invite you to participate and look forward to your input and opinions. Acrobat 3D, AutoCAD, Catia, Inventor, IronCAD, Creo, Pro/ENGINEER, Solid Edge, SolidWorks, and others.

Export BOM

idocadd

New member
How to export a BOM from SolidWorks? Can I :

1. a copy and paste to the Windows clipboard
2. export to a CSV (Comma Separated Variable) file
3. an Excel spreadsheet file (.XLS format)
4. All of the above
 
Yes you can export to .xls below is the code that I use. It also does some sorting that you may not need or have to modify.
Basically it looks for the bom table and the puts that data in excel. There is some basic error proofing as well.

Good luck

Option Explicit




Private Sub CommandButton1_Click()

Dim swApp As New SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swTable As SldWorks.TableAnnotation
Dim bRet As Boolean

' If swApp Is Nothing Then
' Exit Sub


Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
MsgBox ("Solidworks must be running and a drawing with a bom must be active")
Exit Sub
ElseIf swModel.GetType <> swDocDRAWING Then
MsgBox ("Solidworks must be running and a drawing with a bom must be active")
Exit Sub
End If

Set swDraw = swModel
Set swView = swDraw.GetFirstView

Do While Not swView Is Nothing

Set swTable = swView.GetFirstTableAnnotation

Do While Not swTable Is Nothing

ProcessTable swApp, swModel, swTable

Set swTable = swTable.GetNext

Loop
Set swView = swView.GetNextView

Loop


End Sub


Sub ProcessTable _
(swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swTable As SldWorks.TableAnnotation)

Dim swAnn As SldWorks.Annotation
Dim nNumCol As Long
Dim nNumRow As Long
Dim i As Long
Dim j As Long

Set swAnn = swTable.GetAnnotation

nNumCol = swTable.ColumnCount

If nNumCol > 5 Then
Exit Sub
End If

nNumRow = swTable.RowCount



' Get the table contents
Dim curRow As Integer
curRow = 0

i = nNumRow
Do While i >= 0
For j = 0 To nNumCol - 1
Cells(curRow + 4, j + 27).Value = swTable.Text(i, j)
Next j

i = i - 1
curRow = curRow + 1
Loop

' Move descrption column to the right by 1 column

Columns("ac:ac").Select
Selection.Cut
Columns("ae:ae").Select
Selection.Insert Shift:=xlToRight

'Sorts the bom data from SolidWorks

Range("AB6:AD104").Select
Selection.Copy
Range("H7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

' Deletes the SolidWorks data that was copied

Range("AA4:AE104").Select
Selection.Delete

'Go Home
Range("A1").Select

MsgBox ("Finished getting SolidWorks BOM")


End Sub


Private Sub CommandButton2_Click()


Dim swApp As New SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim sModelName As String
Dim nDocType As Long
Dim nErrors As Long
Dim nWarnings As Long
Dim strFileType As String
Dim longstatus As Long
Dim longwarnings As Long


Set swModel = swApp.ActiveDoc

If swModel Is Nothing Then
MsgBox ("Solidworks must be running and a drawing must be active")
Exit Sub
ElseIf swModel.GetType <> swDocDRAWING Then
MsgBox ("Solidworks must be running and a drawing must be active")
Exit Sub
End If

Set swDraw = swModel

' Drawing sheet

Set swView = swDraw.GetFirstView

' First view on the sheet

Set swView = swView.GetNextView

' Determine if this is a view of a part or assembly

sModelName = swView.GetReferencedModelName

sModelName = LCase(sModelName)

If InStr(sModelName, ".sldprt") Then
nDocType = swDocPART
Else
nDocType = swDocASSEMBLY
End If

'MsgBox (sModelName)

Set swDrawModel = swApp.ActivateDoc2(sModelName, False, nErrors)
'__________________________________________________________________________________________

Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim swModelDoc As SldWorks.ModelDoc2
Dim vDwgDependent As Variant
Dim strRev As String
Dim strRevResolved As String
Dim strConfig As String


'get custom property manager for modeldoc
'Set swCustPropMgr = swModelDoc.Extension.CustomPropertyManager(strConfig)
Set swCustPropMgr = custompropertymanger.g


'get revison value
swCustPropMgr.Get2 "Rev", strRev, strRevResolved

'display revision value
MsgBox "Model Revision is " & strRev & " " & "Config: " & strConfig, vbOKOnly, "Example Program"



End Sub
 
Select the BOM in the drawing field and do file>save as
Insert a file name and elect .xls as file type.
for BOMs inserted as Excel based you can also do this by selecting them in feature tree
 

Articles From 3DCAD World

Sponsor

Back
Top