0 Replies Latest reply on Jul 5, 2018 6:17 AM by Chiao Yang Chang

    How to use API to make an animation through mate controller?

    Chiao Yang Chang

      How to use API to make an animation through mate controller?

      In SW2017, I want to use API to make an animation in a motion study by animation wizard which can import the mate controller setting.

      Using Record Macro ,unfortunately, I can't find the key codes about mate controller api and codes about how to import mate controller setting into a motion study.

      There are only codes about selection functions.

       

      [Macro : Mate Controller Setting ]

      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
      boolstatus = Part.Extension.SelectByID2("Links-1@Assem", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
      Dim myComponent As Object
      Set myComponent = Part.SelectionManager.GetSelectedObjectsComponent3(1, 0)
      myComponent.Solving = 1
      boolstatus = Part.EditRebuild3()
      boolstatus = Part.Extension.SelectByID2("Distance1@Links-1@Assem", "MATE", 0, 0, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Distance2@Links-1@Assem", "MATE", 0, 0, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("LimitAngle1@Links-1@Assem", "MATE", 0, 0, 0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("LimitAngle2@Links-1@Assem", "MATE", 0, 0, 0, True, 0, Nothing, 0)
      Part.ClearSelection2 True
      End Sub

       

      [Macro : Mate Controller Setting ]

      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()
      Dim myMotionStudy As Object
      Set myMotionStudy = motionStudyMgr.GetMotionStudy("Motion Study 3")
      boolstatus = myMotionStudy.Calculate()
      End Sub

       

      [Fig1. Mate Controller Setting]

      Mate_Controller_Setting.png

       

      [Fig2. Animation Wizard Setting]

      Input_MateController_into_MotionStudy_Setting.png

       

      [Fig3. Animation in Motion Study]

      MotionStudy_Setting2.png

      MotionStudy_Setting3.png

      MotionStudy_Setting.png