5 Replies Latest reply on Dec 30, 2014 1:52 PM by Brandon Massoni

    Configuration Specific new Features

    Brandon Massoni

      I am cutting a part in such a way that it creates two bodies (parent conf). I need to store each of these bodies in their own configuration (children conf). How can I delete one body for each configuration?


      I tried the following three methods, but the parent and children configurations all have the same features with what I tried (both bodies deleted in all configurations). Code attached.


      1. swModel.ShowConfiguration2()

      2. swConf.Select (False) 'Selects only the current configuration

      3. swModel.FeatureManager.InsertDeleteBody.SetSuppression2 swSuppressFeature, swAllConfiguration, Empty

        • Re: Configuration Specific new Features
          Keith Rice



          What you're trying to accomplish seems very similar to how I create left-hand and right-hand parts. I think the same methodology might apply. I actually have a free video that shows you how to accomplish this in a VBA macro. Check it out.



          SolidWorks API Video Tutorials

            • Re: Configuration Specific new Features
              Brandon Massoni



              Not really. In your example, you never move between configurations, which is what I have trouble with. I can add the configurations and derived configurations easy enough (see code).


              Rather, I need an example of how to use "swConf.SuppressNewFeatures"  or another solution. The link at the bottom of this page EditConfiguration3 options may have been useful if it wasn't broken.

                • Re: Configuration Specific new Features
                  Keith Rice

                  What you're doing is similar because the problem is solved by having the correct configuration active when a feature is created or its suppression state modified. You don't need to get the "Suppress new features" option involved.


                  Your problem statement isn't clear as to whether you want one body suppressed or unsuppressed per configuration, but I am going to assume the latter.




                  'For each body in the part, create a configuration that contains only that body. _

                      All other bodies are suppressed.


                  'Precondition: part is open


                  'Written by Keith Rice

                  'CADSharp LLC



                  Dim swApp As SldWorks.SldWorks

                  Dim swModel As SldWorks.ModelDoc2

                  Dim swPart As SldWorks.PartDoc

                  Dim swFeat As SldWorks.Feature

                  Dim swConfig As SldWorks.Configuration

                  Dim vBodies As Variant

                  Dim i As Integer, j As Integer

                  Dim strOriginalConfigName As String

                  Dim colConfigName As New Collection

                  Dim colDeleteBodyName As New Collection


                  Sub main()

                      Set colConfigName = Nothing

                      Set colDeleteBodyName = Nothing

                      Set swApp = Application.SldWorks

                      Set swModel = swApp.ActiveDoc


                      strOriginalConfigName = swModel.ConfigurationManager.ActiveConfiguration.Name


                      Set swPart = swModel

                      vBodies = swPart.GetBodies2(swAllBodies, False)


                      If IsEmpty(vBodies) Then Exit Sub


                      For i = 0 To UBound(vBodies)

                          Set swConfig = swModel.AddConfiguration3(vBodies(i).Name, Empty, Empty, Empty)

                          colConfigName.Add swConfig.Name

                          swModel.Extension.SelectByID2 vBodies(i).Name, "SOLIDBODY", 0, 0, 0, False, 0, Nothing, 0

                          Set swFeat = swModel.FeatureManager.InsertDeleteBody

                          colDeleteBodyName.Add swFeat.Name

                      Next i


                      For i = 1 To colConfigName.Count

                          swModel.ShowConfiguration2 colConfigName.Item(i)


                          For j = 1 To colDeleteBodyName.Count

                              Set swFeat = swPart.FeatureByName(colDeleteBodyName.Item(j))

                              If j = i Then

                                  swFeat.SetSuppression2 swSuppressFeature, swThisConfiguration, Empty


                                  swFeat.SetSuppression2 swUnSuppressFeature, swThisConfiguration, Empty

                              End If

                          Next j


                      Next i


                      swModel.ShowConfiguration2 strOriginalConfigName


                  End Sub





                  SolidWorks API Video Tutorials

                  1 person found this helpful
                    • Re: Configuration Specific new Features
                      Yong Ning

                      IsSuppressed2→true and false | SOLIDWORKS Forums



                      Private Sub main()

                        Dim Swapp As SldWorks.SldWorks

                        Dim SwModel As SldWorks.ModelDoc2


                        Dim SwFeat As SldWorks.Feature


                        Dim vConfArr As Variant

                        Dim vConfBool As Variant


                          Set Swapp = Application.SldWorks

                          Set SwModel = Swapp.ActiveDoc


                          Set SwFeat = SwModel.FeatureByName("Hole")

                          Debug.Print "Feature: " & SwFeat.Name


                          vConfArr = SwModel.GetConfigurationNames

                          vConfBool = SwFeat.IsSuppressed2(swInConfigurationOpts_e.swSpecifyConfiguration, vConfArr)


                          For i = 0 To UBound(vConfArr)

                              Debug.Print "Configuration: " & vConfArr(i) & "  Suppression: " & vConfBool(i)

                          Next i

                          SwFeat.SetSuppression2 swSuppressFeature, swAllConfiguration, vConfArr


                      End Sub

                      1 person found this helpful