Is it possible to use ChildComponentDisplayInBOM in an assembly to check all subs, or so i need to check all the subs individually?
Is it possible to use ChildComponentDisplayInBOM in an assembly to check all subs, or so i need to check all the subs individually?
This is a property of a configuration of an assembly.
When the assembly is used as a subassembly, this property controls how it is shown in the BOM.
If the assembly is used as a top-level assembly, this property has no meaning.
The property does not cascade down. If this assembly contains subassemblies, each one of them has their own property on a config-by-config basis.
It's just the API way to get to this option:
Try each one yourself to understand how they work.
Josh,
I understand, my issue is i want to run the macro at a top level, and check ALL the subs to find out if it was mistakenly set to Hide. I had an instance where this issue delayed a job 6 weeks because parts in a sub-assembly were never ordered.
No. It's a configuration property. It does not cascade. You can certainly run a macro at the top level, but you will have to check this property for every component. Well, every component that's a .sldasm anyway.
There are 16 billion examples on the forum for how to iterate through all the components of an assembly. I would recommend one that uses GetComponents to grab them all at once rather than a recursive one that examines the tree.
Josh,
I've been able to Traverse the assembly, and get all the sub assemblies, but I'm falling short on the "accessing" ChildComponentDisplayInBOM
I was able to get ChildComponentDisplayInBOM, but it was for the Main Assembly...Not the Subs. Ive been stuck, what i have is below...
Option Explicit
Sub TraverseComponent _
(swComp As SldWorks.Component2, nLevel As Long)
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
Dim CheckPromote As Integer
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
Set swModel = swChildComp.GetModelDoc2
'Set swCompConfig = swConfigMgr.ActiveConfiguration
'CheckPromote = swCompConfig.ChildComponentDisplayInBOM
If swModel.GetType = swDocASSEMBLY Then
Debug.Print sPadStr & swChildComp.Name2 & " <" & swChildComp.ReferencedConfiguration & ">" & CheckPromote
End If
Next i
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent3(True)
' Traverse components
TraverseComponent swRootComp, 1
End Sub
Josh,
I Figured it out my error
I was using swConfigMgr.ActiveConfiguration when i needed swModel.GetActiveConfiguration
Actually you don't want GetActiveConfiguration. You want the configuration referenced by the assembly. You get that from Component2::ReferencedConfiguration.
That's funny, i tried ReferenceConfiguration, but that wouldn't give me access to ChildComponentDisplayInBOM, while GetActiveonfiguration did. It is working correctly
It's working... Adequately. Because you're lucky. Not correctly. If someone saves the subassembly with a different configuration active, your macro will not set the property for the proper configuration, and guess what... You'll miss ordering crap again.
ReferencedConfiguration property of a Component returns a string. That string you can use with ModelDoc2::GetConfigurationByName to return a Configuration object whose properties you can set.
Ya, i figured, this was more a top level question, if anyone had done it...i didn't find to much on the ChildComponentDisplayInBOM. I also added the check for skipping suppressed items.
Option Explicit
Sub TraverseComponent _
(swComp As SldWorks.Component2, nLevel As Long)
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
Dim CheckPromote As Integer
Dim CheckResults As String
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
If swChildComp.IsSuppressed = False Then
Set swModel = swChildComp.GetModelDoc2
Set swCompConfig = swModel.GetActiveConfiguration
CheckPromote = swCompConfig.ChildComponentDisplayInBOM
If CheckPromote = 1 Then
CheckResults = "Hide"
End If
If CheckPromote = 2 Then
CheckResults = "Show"
End If
If CheckPromote = 3 Then
CheckResults = "Promote"
End If
If swModel.GetType = swDocASSEMBLY Then
Debug.Print "Assembly Name: "; swChildComp.Name2
Debug.Print " Configuration: " & swChildComp.ReferencedConfiguration
Debug.Print " Child Component Display When used in a Subassembly: " & CheckResults
End If
End If
Next i
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent3(True)
' Traverse components
TraverseComponent swRootComp, 1
End Sub
As always thanks for the assist
Ya, i figured, this was more a top level question, if anyone had done it...i didn't find to much on the ChildComponentDisplayInBOM. I also added the check for skipping suppressed items.
Option Explicit
Sub TraverseComponent _
(swComp As SldWorks.Component2, nLevel As Long)
Dim swModel As SldWorks.ModelDoc2
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
Dim CheckPromote As Integer
Dim CheckResults As String
For i = 0 To nLevel - 1
sPadStr = sPadStr + " "
Next i
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
If swChildComp.IsSuppressed = False Then
Set swModel = swChildComp.GetModelDoc2
Set swCompConfig = swModel.GetActiveConfiguration
CheckPromote = swCompConfig.ChildComponentDisplayInBOM
If CheckPromote = 1 Then
CheckResults = "Hide"
End If
If CheckPromote = 2 Then
CheckResults = "Show"
End If
If CheckPromote = 3 Then
CheckResults = "Promote"
End If
If swModel.GetType = swDocASSEMBLY Then
Debug.Print "Assembly Name: "; swChildComp.Name2
Debug.Print " Configuration: " & swChildComp.ReferencedConfiguration
Debug.Print " Child Component Display When used in a Subassembly: " & CheckResults
End If
End If
Next i
End Sub
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim swConf As SldWorks.Configuration
Dim swRootComp As SldWorks.Component2
Dim bRet As Boolean
Dim fileName As String
Dim errors As Long
Dim warnings As Long
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConf = swModel.GetActiveConfiguration
Set swRootComp = swConf.GetRootComponent3(True)
' Traverse components
TraverseComponent swRootComp, 1
End Sub
As always thanks for the assist