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.
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
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
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.