View a set of parts

Hello, I managed to hide all the assembly parts in solidworks automatically using VB.net. but I found problems to display some parts to use them later.

I tried this code there

 Sub ShowComp(swApp As SldWorks, swModel As ModelDoc2, swComp As Component2)
        Dim vChildArr as Object
        Dim vChild As Object
        Dim swChildComp As Component2
        Dim swComponentVisible As Integer = 1
       swComp.Visible = swComponentVisible
        vChildArr = swComp.GetChildren
        For Each vChild In vChildArr
            swChildComp = vChild         
            swChildComp.Visible = swComponentVisible
            ShowComp(swApp, swModel, swChildComp)
        Next vChild
    End Sub

sub main ()

     
        Dim vSelComp as Object
        Dim swSelComp As Component2

  Dim swApp As New SldWorks
        Dim swModel As ModelDoc2

 For Each vSelComp In vSelCompArr
            swSelComp = vSelComp
            ShowComp(swApp, swModel, swSelComp)
        Next vSelComp

end sub

 

there is a problem with vSelComp, because the parts I have are in the form of strings, and swSelComp is Component2.

Do you have any idea how this problem can be solved? or do you have any other solution?  and thank you

Good evening, is there a person who can give me an idea on this subject please?

Good evening

Surely there is someone to help you! But you know, there are a lot of professionals on this forum and they come here when they have a little bit of free time.

In addition, VB net is not used by everyone, which also limits the number of people who can help you.

I believe that with a little patience you will have an answer to your question.

Kind regards

5 Likes

Hello

If you managed to hide all the parts of an assembly in VB.net then I guess the code you provide us with is not complete because in your "Sub main()" your variable "swModel" is declared but not initialized and "vSelCompArr" is neither declared nor initialized...

You can find HERE an example in VB.net that shows how to browse an assembly at the component and feature level recursively, analyzing this example should solve your problem.

Kind regards

1 Like