3 Replies Latest reply on May 23, 2018 1:42 AM by Chiao Yang Chang

    How to use a scroll bar to control angle in angle mate?

    Chiao Yang Chang

      I want to use scroll bar to control angle between Link1 & Link2.

      But there's an error in .EditMate4 funtion.

      I'm not sure what's wrong with the code.

       

      Link_problem.PNG

      =================================================================

      Option Explicit
      Const pi = 3.1416159

      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swModelDocExt As SldWorks.ModelDocExtension
      Dim swAssembly As SldWorks.AssemblyDoc
      Dim mate As SldWorks.Mate2

      Dim boolstatus As Boolean
      Dim longstatus As Long

       

      Private Sub hsb_Change()   ' hsb means scroll bar

      Set swApp = Application.SldWorks
      Set swModel = swApp.ActiveDoc
      Set swModelDocExt = swModel.Extension
      Set swAssembly = swModel

       

      ' Mate
      swModel.ClearSelection2 True
      boolstatus = swModelDocExt.SelectByID2("Angle1", "MATE", 0, 0, 0, False, 0, Nothing, 0)
      boolstatus = swModelDocExt.SelectByID2("Front Plane @ Link-1 @ Link_Assemble", "PLANE", 0, 0, 0, False, 1, Nothing, 0)
      boolstatus = swModelDocExt.SelectByID2("Front Plane @ Link-2 @ Link_Assemble", "PLANE", 0, 0, 0, False, 1, Nothing, 0)

      Set mate = swAssembly.EditMate4(swMateType_e.swMateANGLE, swMateAlign_e.swMateAlignALIGNED, False, 0, 0.001, 0.002, 0, 0.001, hsb.Value, 5, 0, False, False, 0, False, longstatus)

      swModel.ClearSelection2 True
      swModel.EditRebuild3

       

      ' Redraw
      swModel.GraphicsRedraw2

      End Sub

       

      Private Sub UserForm_Activate()
      hsb.Max = 5
      hsb.Min = 0
      hsb.SmallChange = 1

      End Sub

        • Re: How to use a scroll bar to control angle in angle mate?
          Jacob Corder

          boolstatus = swModelDocExt.SelectByID2("Angle1", "MATE", 0, 0, 0, False, 0, Nothing, 1)

          boolstatus = swModelDocExt.SelectByID2("Front Plane @ Link-1 @ Link_Assemble", "PLANE", 0, 0, 0, False, 1, Nothing, 1)

          boolstatus = swModelDocExt.SelectByID2("Front Plane @ Link-2 @ Link_Assemble", "PLANE", 0, 0, 0, False, 1, Nothing, 1)

           

          Try this

           

          select options should be Extensive for multiple selection.  you were clearing the selection per SelectByID2

           

          • Re: How to use a scroll bar to control angle in angle mate?
            Michael Spens

            Hello Chiao,

            I think you'll find better behavior by modifying the angle dimension rather than editing the feature every time.  You might also want to use the Scroll method of the scroll bar.  Move your connections to SOLIDWORKS and the model to the form's Activate method to optimize your processing.  FYI, I changed the scroll bar Max and SmallChange values since my example was in degrees, not radians.  Verify the angle dimension name in your assembly.  Mine was D1@Angle1.

             

            Private Sub UserForm_Activate()

            hsb.Max = 90

            hsb.Min = 0

            hsb.SmallChange = 15

             

            Set swApp = Application.SldWorks

            Set swModel = swApp.ActiveDoc

            Set swModelDocExt = swModel.Extension

            Set swAssembly = swModel

             

            End Sub

             

            Private Sub hsb_Scroll()

             

            Dim myDim As Dimension

            Set myDim = swModel.Parameter("D1@Angle1")

            myDim.SetValue3 hsb.Value, swSetValue_UseCurrentSetting, Nothing

             

            swModel.EditRebuild3

             

            ' Redraw

            swModel.GraphicsRedraw2

            End Sub