Macro SW Feature manager Filter

Hello
I would like to make a macro where I can add a piece of data in the feature manager filter (1):
image
And if possible, check if zone 2 is empty or not after the filter.
If empty, the filter is removed.
If not empty msgbox

The most important thing is to be able to add or remove a piece of data from the filter, the verification (life or not empty) would remain secondary.
I found this function without really having an example:
image
If anyone has an example or idea of how to use this function.

Bonjour;
Bah, comme souvent il y a CodeStack: (Non testé)

1 Like

I saw this code but for me it doesn't use the filter and on large assemblies like me, I think the search will be much slower.
If I really have no choice I'd go for it.
But our solution via the filter seems very fast by typing it by hand?
I just want to automate this search by integrating it into another macro.
And if possible then add the search once filtered if=0 no message and if >0 message

Technically the use of the fitre looks like this:

Sub FiltrerFeatureManager()
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim searchText As String

    ' Initialiser l'application SolidWorks
    Set swApp = Application.SldWorks
    ' Obtenir le modèle actif
    Set swModel = swApp.ActiveDoc

    ' Vérifier si un document est ouvert
    If swModel Is Nothing Then
        MsgBox "Aucun document ouvert."
        Exit Sub
    End If

    ' Définir le texte de recherche
    searchText = "Rondelle"

    ' Définir le texte de filtrage dans le FeatureManager
    swModel.Extension.FeatureManagerFilterString = searchText

    ' Forcer la mise à jour de l'interface utilisateur
    swModel.GraphicsRedraw2
End Sub

It works, in this example, only the " washers " are filtered. Only there is a problem (and not the least), I can't manage to " cancel " the filtration...

1 Like

I just tested this code step by step:

Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Dim value As String
Dim value2 As String

Sub main()
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
    Set swModelDocExt = swModel.Extension


    value = "Tôle passage réduit"
    'value = swModelDocExt.FeatureManagerFilterString
    swModelDocExt.FeatureManagerFilterString = value
    value2 = swModelDocExt.FeatureManagerFilterString
    Debug.Print value2
    swModelDocExt.FeatureManagerFilterString = ""
    'swModel.ClearSelection2 True
End Sub

The filter applies to the graphics window (CAD part), only my filtered part appears in this graphic area.
On the other hand, the feature manager remains fixed. (complete tree structure of the assembly and nothing apparent in the filter.
Bug in my 2023 SP05 version or normal behavior?
Or bad function?

@Maclane to cancel a filter you have to put "  " in value or searchtext="  " for your code

Same behavior with your code:

Only the washers appear on the right.
But nothing in the feature manager.
Macro method:
image
Manual method:
image

under Solidworks 2022 the same observation, only the graphical view is impacted.

1 Like

@sbadenis : at your place also the order:
searchtext=« »
Is incredibly slow?

I tried with:
searchtext= vbNullString
but it's not better...

1 Like

Have you looked at the TreeManager side of the Mycad tools (it's hidden in the "reference tools" drop-down):
image

This obviously does not meet all your needs but it is also an option for multi-criteria filtration:
image

Note: I really have a hard time understanding the Visiativ logic which consists of hiding their tools, or even not installing them by default anymore... it does not encourage consumption...


there may be another possible path by going through The Advanced Selections.
image
(often forgotten option of Solidworks).

Some VBA examples are available in the API Helps:
https://help.solidworks.com/2022/english/api/sldworksapi/Use_Advanced_Component_Selection_Example_VB.htm?verRedirect=1
https://help.solidworks.com/2022/english/api/sldworksapi/solidworks.interop.sldworks~solidworks.interop.sldworks.iadvancedselectioncriteria.html
Edit: I just realized that this is the function used by the CodeStack macro mentioned above...

2 Likes

@Maclane Yes for me too it takes " 2 hours " to refresh the view!
For the use of TreeManager, not possible I want to add this in an existing macro.
If I go through an ext utility in SW the designers will not do it systematically and behind it generates errors parts to be replaced not detected.
For the limited number of utilities I think it's not due to Visiativ but Windows or Dassault I don't know, who created this limitation (Cf hotline)
For the advanced selection, I just tested it works for parts in the assembly but in a subassembly it no longer finds the part.
It seemed perfect!

1 Like