1 Reply Latest reply on Aug 16, 2018 6:39 AM by Sergio Monti

    How to use API to edit dimension value of the mate in motion study?

    Chiao Yang Chang

      How to use API to edit dimension value of the mate in motion study?

      In manual method,I can edit dimension value of mate in motion study.

       

      Edit dimension in motion study.png

      I also record the macro when editing.

      But when I run the macro, it can't present the same results as in the manual method.

      In the macro, it can't edit dimension value of mate in motion study.

      What's wrong with the code?

      There are complete files in the attached file.

       

      [Macro]

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

      Option Explicit
      Dim swApp As Object

      Dim Part As Object
      Dim boolstatus As Boolean
      Dim longstatus As Long, longwarnings As Long

      Sub main()

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc
      Dim motionStudyMgr As Object
      Set motionStudyMgr = Part.Extension.GetMotionStudyManager()
      boolstatus = motionStudyMgr.ActivateMotionStudy("Motion Study 1")
      Set motionStudyMgr = Part.Extension.GetMotionStudyManager()
      Dim myMotionStudy As Object
      Set myMotionStudy = motionStudyMgr.GetMotionStudy("Motion Study 1")
      boolstatus = myMotionStudy.SetTime(2)


      boolstatus = Part.Extension.SelectByID2("LimitAngle1", "MATE", 0, 0, 0, False, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("LimitAngle1", "MATE", 0, 0, 0, False, 0, Nothing, 0)


      Dim myDimension As Object
      Set myDimension = Part.Parameter("D1@LimitAngle1")
      myDimension.SystemValue = 1.570796326795


      boolstatus = Part.Extension.SelectByID2("LimitAngle2", "MATE", 0, 0, 0, False, 0, Nothing, 0)
      Set myDimension = Part.Parameter("D1@LimitAngle2")
      myDimension.SystemValue = 0.7853981633975


      Part.ClearSelection2 True
      Set motionStudyMgr = Part.Extension.GetMotionStudyManager()
      Set myMotionStudy = motionStudyMgr.GetMotionStudy("Motion Study 1")
      boolstatus = myMotionStudy.Calculate()
      End Sub

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