Hello I would like to make a macro where I can add a piece of data in the feature manager filter (1): 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: If anyone has an example or idea of how to use this function.
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
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...
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
Have you looked at the TreeManager side of the Mycad tools (it's hidden in the "reference tools" drop-down):
This obviously does not meet all your needs but it is also an option for multi-criteria filtration:
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. (often forgotten option of Solidworks).
@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!