Thanks for your help everyone. I do appreciate the time you've taken. With your help, I've figured out what I needed to do.
Now I have another question. First, here's the code I've used so far to traverse an assembly and it's components:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const swDocAssembly = 2
Option Explicit
Public docType As Integer
Public swApp As SldWorks.SldWorks
Public swModel As SldWorks.ModelDoc2
Dim returnOK As Boolean
Public Part As Object
Private Sub Main()
Dim swRootComp As SldWorks.Component2
Dim swConf As SldWorks.Configuration
Set swApp = CreateObject("SldWorks.Application")
swApp.visible = True
Set swModel = swApp.ActiveDoc
If swModel Is Nothing Then
Call MsgBox("A SolidWorks document needs to be loaded!", vbExclamation, "Custom Properties") ' Display error message
returnOK = False
swApp.visible = True
End ' If no model currently loaded, then exit
Else
docType = swModel.GetType
If (docType = swDocAssembly) Then
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent
Open "C:\BOM Export Files\Output.txt" For Output Access Write Lock Write As #1
'Traverse assembly
TraverseComponent swRootComp
Close #1
Else
MsgBox ("File is not assembly")
End 'Exit if file is not assembly
'Code for parts and drawings to be added later
End If
End If
End Sub
Sub TraverseComponent(swComp As SldWorks.Component2)
'this recursively traverses all of the components in an assembly
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim ModName As String
Dim i As Integer
Dim vChildComp2 As Variant
Dim i2 As Integer
Dim swChildComp2 As SldWorks.Component2
Dim vChildComp3 As Variant
Dim i3 As Integer
Dim swChildComp3 As SldWorks.Component2
'Get the childrent of this component
vChildComp = swComp.GetChildren
'Get children on 1st level
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
ModName = swChildComp.Name
'Set the Part object
Set Part = swChildComp.GetModelDoc()
If Not swChildComp.IsSuppressed() And Not swChildComp.ExcludeFromBOM Then
Print #1, swChildComp.Name
'Set the Child variant
vChildComp2 = swChildComp.GetChildren
'Get children on 2nd level
For i2 = 0 To UBound(vChildComp2)
Set swChildComp2 = vChildComp2(i2)
Set Part = swChildComp2.GetModelDoc()
If Not swChildComp2.IsSuppressed() And Not swChildComp2.ExcludeFromBOM Then
Print #1, swChildComp2.Name
'Set the Child variant
vChildComp3 = swChildComp2.GetChildren
'Get childrent on 3rd level
For i3 = 0 To UBound(vChildComp3)
Set swChildComp3 = vChildComp3(i3)
Set Part = swChildComp3.GetModelDoc()
If Not Part.IsSuppressed And Not Part.ExcludeFromBOM Then
Print #1, swChildComp3.Name
End If
Next i3
End If
Next i2
End If
Next i
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
The problem I'm having is where I use If...Then statements to skip any SUPRESSED components and those with an "EXCLUDE FROM BOM" property defined.
I've set a watch to "trip" when either "suppressed" or "exclude" is TRUE. The problem is that (with my IF NOT and AND NOT statements) the statement is supposed to execute as long as the component is neither suppressed nor excluded from BOM, but it executes regardless of the returned value.
How can this be? I've tried running the same code with different expressions (If Not 2 = 3 And Not 3 = 3 Then) and I get the same results...
Help!!
Thanks again
