5 Replies Latest reply on Apr 13, 2015 6:42 AM by Ruud Strauven

    Feature doesn't unsuppress in VBA Macro

    Ruud Strauven

      I want to unsuppress a feature in a part when the length of the part is higher then a certain value, but EditUnsuppress doesn't work.

      Feature is suppressed in part.

      The macro contains the following lines:

       

      If Height.Value > 1200 Then

              Set Part = swApp.ActiveDoc

              Set myModelView = Part.ActiveView

              myModelView.FrameLeft = 0

              myModelView.FrameTop = 0

              Set myModelView = Part.ActiveView

              myModelView.FrameState = swWindowState_e.swWindowMaximized

       

              swApp.ActivateDoc2 "401-163-0002^" & code & "-001-000x.SLDPRT", False, longstatus

            

      MsgBox "Bigger"

          

             boolstatus = Part.Extension.SelectByID2("Cut-Extrude4", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

             Part.EditUnsuppress2

       

      Anyone any suggestions?

        • Re: Feature doesn't unsuppress in VBA Macro
          Keith Rice

          Is the feature actually getting selected after you run IModelDocExtension::SelectByID2? In the VB Editor, step through your code with F8. After the SelectByID2 line is executed, see in SolidWorks if the feature is actually selected. If not, you might have the name wrong.

           

          This API call works fine, which you can see in the following example:

           

          1. Create a new part document

          2. Create an extrude base feature

          3. Make sure that the name of the extrude base feature is "Extrude-Boss1"

          4. Suppress the base extrude feature

          5. Create a new macro with this code:

           

          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          
          Sub main()
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              swModel.Extension.SelectByID2 "Boss-Extrude1", "BODYFEATURE", _
                  0, 0, 0, False, 0, Nothing, 0
              swModel.EditUnsuppress2
          End Sub
          

           

          6. Run the code

          Result: the feature should be unsupressed

           

          Keith

          SolidWorks API Training

          • Re: Feature doesn't unsuppress in VBA Macro
            Deepak Gupta

            Why don't simply add an equation which can suppress/unsuppress the feature if value is in/out of limit.

            • Re: Feature doesn't unsuppress in VBA Macro
              Ivana Kolin

                      Set myModelView = Part.ActiveView

                      myModelView.FrameLeft = 0

                      myModelView.FrameTop = 0

                      Set myModelView = Part.ActiveView

                      myModelView.FrameState = swWindowState_e.swWindowMaximized

               

                      swApp.ActivateDoc2 "401-163-0002^" & code & "-001-000x.SLDPRT", False, longstatus

                      Set Part = swApp.ActiveDoc

                 

              MsgBox "Bigger"

                 

                     boolstatus = Part.Extension.SelectByID2("Cut-Extrude4", "BODYFEATURE", 0, 0, 0, False, 0, Nothing, 0)

                     Part.EditUnsuppress2