Trying to select all components in Assembly tree that are suppressed. I can't get it to recognize the suppression. My suppressed variable always shows false regardless if the component is suppressed or not. Here is my code. What am I doing wrong?
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim fileerror As Long
Dim filewarning As Long
Dim swFeatMgr As SldWorks.FeatureManager
Dim swSelMgr As SldWorks.SelectionMgr
Dim nErrors As Long
Dim nWarnings As Long
Dim swFeat As SldWorks.Feature
Dim boolstatus As Boolean
Dim swModelDocExt As ModelDocExtension
Dim featName As String
Dim vConfNameArr As Variant
Dim vSuppStateArr As Variant
Dim suppressed As Boolean
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Set swModel = swApp.ActiveDoc
Set swFeat = swModel.FirstFeature
Do Until swFeat.GetTypeName2 = "Reference"
Set swFeat = swFeat.GetNextFeature 'get next component in the tree
Loop
Do While swFeat.GetTypeName2 <> "MateGroup"
If swFeat.GetTypeName2 = "Reference" Then 'is feature a sw file
Debug.Print swFeat.Name
vConfNameArr = swModel.GetConfigurationNames
vSuppStateArr = swFeat.IsSuppressed2(swThisConfiguration, vConfNameArr)
suppressed = vSuppStateArr(0)
Debug.Print vSuppStateArr(0)
If suppressed = True Then
swFeat.Select (True) ' select
End If
'Debug.Print swFeat.isSuppressed
Set swFeat = swFeat.GetNextFeature
Else
Set swFeat = swFeat.GetNextFeature
End If
Loop
End Sub
Thanks for your help
SolidworksApi/macros
There's a section in this example for getting visibility, fixed or suppressed states.
2019 SOLIDWORKS API Help - Traverse FeatureManager Design Tree Example (VBA)
I tested both. app works better:
Glad it works !
I did try it and it took about the same amount if time to select.
Haven't you tried the solution as that should be much faster than traversing the feature tree.
Thanks Amen, that works great! I was using iFeature because I am slowly learning the API. Still learning all of the right calls to use in what scenarios. Thank you for your help.
As Deepak suggested there seems to be no API support for the selection command. However with a combination of SOLIDWORKS and Windows API it is possible to call this command. Here is an example: Select all suppressed components in the assembly using SOLIDWORKS API
OK, go with codes from
BTW I could not find codes for Component Selection > Select Suppressed
I am looking to select all of the suppressed components and then ultimately delete them. In my code I am looking for item types of "Reference", which as you know are parts and assemblies in the tree. I saw that IsSuppressed was a member of IFeature, so I thought I could use that to check if the component was suppressed or not and then select them. It doesn't appear to work. Looks like I have to use SldWorks.Component2 instead to check isSuppressed.
From your codes, it seems that you are looking to select suppressed mates. So what is your end need and what you want to do with the selection?
If you are trying to get the suppression state of the components, you need to get components, not features.
Try the below code, its a mash of:
Get Component Supression - Example
Traverse the Assembly at component level - example
Option Explicit
Sub TraverseComponent _
(swComp As SldWorks.Component2, nLevel As Long)
Dim vChildComp As Variant
Dim swChildComp As SldWorks.Component2
Dim swCompConfig As SldWorks.Configuration
Dim sPadStr As String
Dim i As Long
vChildComp = swComp.GetChildren
For i = 0 To UBound(vChildComp)
Set swChildComp = vChildComp(i)
TraverseComponent swChildComp, nLevel + 1
Debug.Print swChildComp.Name & " " & swChildComp.IsSuppressed
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)
Debug.Print "File = " & swModel.GetPathName
' Traverse components
TraverseComponent swRootComp, 1
End Sub
Deepak, is there an API call for that?
Have you tried this inbuilt function?
Why are you traversing the entire feature tree using IFeature? If you are working off an assembly and want to select all suppressed components. Just do this: