×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Bill of Material

Bill of Material

Bill of Material

(OP)
Hey everyone

does anyone here know how to traverse a BOM via VBA in Solidworks?

RE: Bill of Material


Enter "traverse a BOM" in the Google search at the top-centre of this page. Make sure the Eng-Tips Forums option is selected.

cheers
SW07-SP3.1
SW06-SP5.1

RE: Bill of Material

(OP)
thanks, I think I may have found a thread that will help.

RE: Bill of Material

(OP)
ok, I need a bit of help with this code...

I am using the code from this thread, [url]http://eng-tips.com/viewthread.cfm?qid=20992[/url] and modified it a bit.

Here is the code below, I can not get it to find the BOM. Any help would be greatly appreciated.

CODE

Option Explicit

Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.DrawingDoc
Dim swView As SldWorks.View
Dim swBOM As SldWorks.BomTable

Sub ReadBOM()
    Dim ret As Variant
    Dim i As Integer
    Dim iItems As Integer
    
    'Get Document
    Set swPart = swApp.ActiveDoc
    
    'Get Drawing Template (first view)
    Set swView = swPart.GetFirstView
    
    'Get the BOM
    Set swBOM = swView.GetBomTable
    
    'Find the BOM - must find the view that contains the BOM
    Do While swBOM Is Nothing And Not swView Is Nothing
        Set swView = swView.GetNextView
        Set swBOM = swView.GetBomTable
    Loop
    If swBOM Is Nothing Then
        'Screen.MousePointer = vbDefault
        MsgBox "Can NOT find the BOM on the current drawing!"
        GoTo CleanUp
    End If
    
    'Attach to the BOM
    ret = swBOM.Attach2
    If ret = False Then
        MsgBox "Error Attaching to BOM"
        Exit Sub
    End If
    
    iItems = swBOM.GetRowCount - 1
    For i = 1 To iItems
        MsgBox swBOM.GetEntryText(i, 0) & "|" & _
               swBOM.GetEntryText(i, 1) & "|" & _
               swBOM.GetEntryText(i, 2) & "|" & _
               swBOM.GetEntryText(i, 3) & "|" & _
               swBOM.GetEntryText(i, 4) & "|"
    Next i
    swBOM.Detach
    
CleanUp:
    Set swApp = Nothing
    Set swPart = Nothing
    Set swView = Nothing
    Set swBOM = Nothing
End Sub

RE: Bill of Material

That's old code, used for getting Excel-based BOMs.  To access SolidWorks BOMs (Introduced with '05, I think) you have to use different calls.  

1. swBOM should be declared as a Sldworks.TableAnnotation rather than Sldworks.BomTable

2. Instead of swView.GetBomTable, you need to use swViw.GetFirstTableAnnotation.  If a table is returned, you need to test and see it is a BOM table annotation with swBOM.Type.  

That should be enough to get you pointed in the right direction in the SW API help.

RE: Bill of Material

(OP)
got it to work, thanx for pointing me in the right direction.

RE: Bill of Material

No problem.  On re-read, my post looks a bit brusque.  Sorry about that.  I was trying to get gone for lunch.  smile

RE: Bill of Material

(OP)
not a problem...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources