5 Replies Latest reply on Sep 30, 2016 6:10 AM by Yong Ning

    IsSuppressed2→true and false

    Yong Ning

      2010 SolidWorks API Help - Is Feature Suppressed in Specified Configurations Example (VBA)

      http://help.solidworks.com/2010/english/api/sldworksapi/IS_Feature_Suppressed_in_Specified_Configurations_Example_VB.htm

       

       

       

      00.jpg

       

       

       

      01.jpg

       

       

      Private Sub del1419()

         Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

            Set SwApp = Application.SldWorks

            Set SwModel = SwApp.ActiveDoc

         Dim SwFeat As Feature

            Set SwFeat = SwModel.FeatureByName("Dn500")

            Debug.Print SwFeat.Name

         Dim ConfArr, vConfArr

            ConfArr = SwModel.GetConfigurationNames

            vConfArr = SwFeat.IsSuppressed2(3, ConfArr)

            Stop

      End Sub

       

      *****************************************************************************

       

      00.jpg

       

      Private Sub ll()

        Dim Swapp As SldWorks.SldWorks, SwModel As ModelDoc2

          Set Swapp = Application.SldWorks

          Set SwModel = Swapp.ActiveDoc

        Dim SwFeat As Feature

          Set SwFeat = SwModel.FeatureByName("Dn400")

          Debug.Print SwFeat.Name

        Dim ConfArr, vConfArr

          ConfArr = SwModel.GetConfigurationNames

          vConfArr = SwFeat.IsSuppressed2(0, ConfArr)

          Stop

          vConfArr = SwFeat.IsSuppressed2(1, ConfArr)

          Stop

          vConfArr = SwFeat.IsSuppressed2(2, ConfArr)

          Stop

          vConfArr = SwFeat.IsSuppressed2(3, ConfArr)

          Stop

      End Sub

        • Re: IsSuppressed2→true and false
          Daniel Andersson

          Hello Yong,

           

          I do not follow what you want to do. I noted in the first image that you point out you have configuration Dn500 active and that the feature Dn400 is not suppressed. I tried to open the attached SolidWorks files but they seems to be damaged some how.

           

          Are you looking for a macro that shows the suppression state for each configuration of the specified feature?

           

          If so, try this code. Please note that you have to change SwModel.FeatureByName to fit your needs.

           

          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("Chamfer1")

              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

          End Sub

            • Re: IsSuppressed2→true and false
              Yong Ning

              Thank you Mr  Daniel Andersson,Thank you reply.

              Where your from Mr Daniel Andersson. Is English your first language?

              I am Chinese, First language is Chinese, can read English, but write english is very bad.

               

              ********************************************************************************

              Run this code → Set SwFeat = SwFeatMgr.InsertTableDrivenPattern(FileName, Nothing, True, True) → Need Suppressed Feature.

              Can use code is very slow. for ii = 0 to ubound(confArr) → need 10 min.

               

              Function EditSupp(SwModel As ModelDoc2, SwConfName)

                 Dim ConfArr, ii, jj, SwFeat As Feature

                    ConfArr = SwModel.GetConfigurationNames

                    ''

                    For ii = 0 To UBound(ConfArr)

                       SwModel.ShowConfiguration2 ConfArr(ii)

                       For jj = 0 To UBound(ConfArr)

                         Set SwFeat = SwModel.FeatureByName(ConfArr(jj))

                         If Not SwFeat Is Nothing Then

                            If SwFeat.Name = SwConfName Then

                              SwFeat.Select True

                              SwModel.EditUnsuppress2

                            Else

                               SwFeat.Select True

                            End If

                            SwFeat.Select True

                         End If

                       Next jj

                       SwModel.EditSuppress2

                       printTiming T

                    Next ii

               

                    SwModel.ShowConfiguration2 SwConfName

                    ''

              End Function

               

              ********************************************************************

               

              this sentence is very simple.

                SwFeat.SetSuppression2 swSuppressFeature, swAllConfiguration, vConfArr

               

              this sentence = Follow code,

              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

                  Stop

              End Sub

                • Re: IsSuppressed2→true and false
                  Daniel Andersson

                  Hi Yong,

                   

                  It looks like you have solved the issue and improved the speed with the your subs SetSuppSwSuppressFeature and unSuppSwSuppressFeature.

                  Going this way eliminates the usage of method IModelDoc2::ShowConfiguration2 which previously slowed down your code.

                   

                  So I assume that you have solved your question. Just let me know otherwise.

                   

                  My first language is Swedish, second is English.

                  (I once knew how to order a beer in Chinese, but that is since long time forgotten.)

                  • Re: IsSuppressed2→true and false
                    Yong Ning

                    Private Sub del0930()

                       Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                           Set SwApp = Application.SldWorks

                           Set SwModel = SwApp.ActiveDoc

                       Dim SwSelMgr As SelectionMgr

                           Set SwSelMgr = SwModel.SelectionManager

                       Dim SwFeat As Feature, vConfArr

                           Set SwFeat = SwSelMgr.GetSelectedObject5(1)

                           'SwFeat.SetSuppression True

                           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

                           SwFeat.SetSuppression2 swComponentFullyResolved, swAllConfiguration, vConfArr

                           Stop

                           Stop

                      

                    End Sub