2 Replies Latest reply on Aug 12, 2015 4:55 AM by Jan Forkovic

    Surface bodies in design tree

    Blandine Ganivet

      Hi everybody,

      I would like to know if it's possible to select all the components in the folder Surface bodies which are in the design tree?

      Thank you for your help

        • Re: Surface bodies in design tree
          Keith Rice

          Hi Blandine,

           

          The following code will accomplish this. Please note that I have given you two options for selection. One will select the bodies in the display area but not the feature tree, the other will select in both. Please comment the line you don't want.

           

          I used the attached part for my testing.

           

          ======

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swFeat As SldWorks.Feature

          Dim swBodyFolder As SldWorks.BodyFolder

          Dim swBody As SldWorks.Body2

          Dim vBodies As Variant

          Dim i As Integer

           

          Sub main()

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

           

              swModel.ClearSelection2 True

           

              Set swFeat = swModel.FirstFeature

              Do While Not swFeat Is Nothing

                  If swFeat.GetTypeName = "SurfaceBodyFolder" Then

                      Set swBodyFolder = swFeat.GetSpecificFeature2

                      vBodies = swBodyFolder.GetBodies

                      For i = 0 To UBound(vBodies)

                          Set swBody = vBodies(i)

           

                          'Option 1: Select bodies in display area but not in feature tree

                          'swBody.Select2 True, Nothing

           

                          'Option 2: Select bodies in display area and in feature tree

                          swModel.Extension.SelectByID2 swBody.Name, "SURFACEBODY", 0, 0, 0, True, 0, Nothing, 0

                      Next i

                      Exit Do

                  End If

                  Set swFeat = swFeat.GetNextFeature

              Loop

          End Sub

           

          ======

           

          Hope this helps.

           

          Keith

          SolidWorks API Tutorials