[SolidWorks] Filter Macro (VBA)

Hello

 

I would like to create a filter macro (In my company, all assemblies are composed on the same model). So I'd like to be able to create a macro that hides everything and displays only certain parts (based on the NAME of the file).

Also a macro that would redisplay everything..

 

Thank you.

 

[edit] The problem above all is to "parse" all the components in the assembly. Is there a way to do this in a for loop?

Hello

If you have the Mycadtools utilities, there is the TreeManager app that might just help you do that.

Have a nice day.

1 Like

Thank you

 

Unfortunately, I will not be able to access the MyCadTools utilities.

So I really need to be able to do it with a macro, and as I said the big problem is currently to take all the elements in an assembly.

Hello, in the tutorials I posted on Lynkoa, there are one or two examples to go through all the components of an assembly. Otherwise, to filter, see the SolidWorks Advanced Selection.
1 Like

Hello, thank you.

Could you give me a link to one of your tutorials or are you talking about that?

It's true that it's impossible to find tutorials made by one person, sorry. I was talking about this tutorial but in fact it concerns all the configurations of an assembly:

http://www.lynkoa.com/tutos/solidworks/macro-pour-toutes-les-configurations-d-un-assemblage-pour-activer-l-option-"promote" I'm looking for the macro I did but it's not on Lynkoa.

1 Like

I found something on the internet that allows me to browse the components of an assembly, the problem is that I can't hide them. What for?

 

Sub main()
    Dim swModel As ModelDoc2
   
    Dim vComps as Variant
    Dim swComp As SldWorks.Component2
    Dim swAssy As SldWorks.AssemblyDoc
    Dim i as Integer
   
    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
   
    If swModel.GetType = swDocASSEMBLY Then
        Set swAssy = swModel
        vComps = swAssy.GetComponents(False)
        For i = 0 TB UBound(vComps)
            Set swComp = vComps(i)
            Set swModel = swComp.GetModelDoc2
            Debug.Print swModel.GetTitle
            swModel.HideComponent2 'Not working...
            swModel.ClearSelection2 True
        Next i
    End If
End Sub

 

[edit]

I found a way to take back the ID with:

            Debug.Print swComp.GetSelectByIDString
            boolstatus = Part.Extension.SelectByID2(swComp.GetSelectByIDString, "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
            Part.HideComponent2

 

So for the moment I think my problem should be solved. I'll wait a little longer before putting it in resolution. Thank you!

1 Like

Indeed, as indicated in the link below, you have to select the component with HideComponent2 , or else they offer another method with visibility:

https://books.google.fr/books?id=ftVsBgAAQBAJ&pg=PA39&lpg=PA39&dq=HideComponent2&source=bl&ots=11v9gfMep9&sig=Kdp-G1le6iPqcbxSFNSueTQXQs4&hl=fr&sa=X&ved=0CCwQ6AEwAmoVChMI-6DIiZuyxwIVAr0aCh3dXQmW#v=onepage&q=HideComponent2&f=false

 

1 Like

Thanks to you, I consider the problem solved.