3 Replies Latest reply on May 9, 2017 12:31 AM by Raisoddin Patel

    How to delete existing structural member group in solidworks API

    Raisoddin Patel

      I am trying to automate weldment part, so user can add multiple instances in sketch pattern. When I change number of instances in sketch patter it only add sketch (image 2). Then I manually add sketch in the group, then it work fine. I want to automate this by in API. I tried using recording macro too.


      Anybody have idea about how to delete existing structural member group or update existing sketches in the group in solidworks API (image 1) ?

      Thanks in advance.


        • Re: How to delete existing structural member group in solidworks API
          Peter Brinkhuis

          The macro recorder indeed doesn't record changes to a weldment. It does record creating structural members though, that helped me to get started. I haven't worked with them either, but here's the route I think you should follow:


          1. You can traverse the feature tree until you get to a feature where GetTypeName2 equals WeldMemberFeat
          2. You can then use swFeat.GetDefinition and put that into a StructuralMemberFeatureData object.
          3. Use that to get to the groups
          4. Change the sketch segments in the groups


          Another thing I found: you can use the IFeatureManager object to add groups, members and other weldment items.


          Good luck

            • Re: How to delete existing structural member group in solidworks API
              Raisoddin Patel

              Thanks Peter,

              as you suggested code is written as :

              Later no idea how to make the change to remove group OR to add new skech in the existing group. Also tried for modifydefinition but nothing happened.




              Option Explicit


              Sub main()


              Dim swApp As SldWorks.SldWorks

              Dim Part As ModelDoc2

              Dim boolstatus As Boolean

              Dim FeatMgr As FeatureManager

              Dim SelMgr As SelectionMgr

              Dim swWeldFeat As SldWorks.Feature

              Dim swWeldFeatData As SldWorks.StructuralMemberFeatureData

              Dim Group2 As StructuralMemberGroup

              Dim j, i As Integer

              Dim vGroups As Variant

              Dim vSegments As Variant


              Set swApp = Application.SldWorks

              Set Part = swApp.ActiveDoc

              Set FeatMgr = Part.FeatureManager

              Set SelMgr = Part.SelectionManager

              Part.ClearSelection2 True

              Dim myFeature As Object

              boolstatus = Part.Extension.SelectByID2("Structural Member1", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

              Set swWeldFeat = SelMgr.GetSelectedObject6(1, 0)

              Set swWeldFeatData = swWeldFeat.GetDefinition

              vGroups = swWeldFeatData.Groups

              Set Group2 = vGroups(1)

                          Debug.Print " Segment Count in Group " & i + 1 & "  : " & Group2.GetSegmentsCount; ""

                          Debug.Print " Rotational angle of group: " & Group2.Angle

                          Debug.Print " ApplyCornerTreatment: " & Group2.ApplyCornerTreatment

                          Debug.Print " CornerTreatmentType: " & Group2.CornerTreatmentType

                          Debug.Print " MirrorProfile: " & Group2.MirrorProfile

                          Debug.Print " MirrorProfileAxis: " & Group2.MirrorProfileAxis

                          Debug.Print " GapWithinGroup: " & Group2.GapWithinGroup

                          vSegments = Group2.Segments

                          For j = LBound(vSegments) To UBound(vSegments)

                              vSegments(j).Select False

                          Next j


              End Sub