Bill of Material
Bill of Material
(OP)
Hey everyone
does anyone here know how to traverse a BOM via VBA in Solidworks?
does anyone here know how to traverse a BOM via VBA in Solidworks?
When was the last time you drove down the highway without seeing a commercial truck hauling goods?
Download nowINTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS Come Join Us!Are you an
Engineering professional? Join Eng-Tips Forums!
*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting GuidelinesJobs |
|
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.
SW07-SP3.1
SW06-SP5.1
RE: Bill of Material
RE: Bill of Material
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
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
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
RE: Bill of Material
RE: Bill of Material