Problem during creation motor linear with vba macro

Hello everybody,

I have writen a vba macro whoch create one (or more) linear motor to move a sphere and make an animation. In fact, i want to study the displacement of different point in the 3 dimension of space. So my idea was to create sphere on solidworks, make an assembly where i place it, and then apply 3 motor (one for x composant of displacement, one for y and one for z) for each sphere. And after, i will just have to click one play and see the animation.

My problem i that my vba macro create all my motor with all the parameter, but when i click on "calculate the animation" and after on "play", nothing move.

I have to make on each motor:

- right clik

- modify

- change nothing and validate

And now, i click on "calculate the animation" and after on "play" and all move correctely !!

I don't understand what is appening......

Have anybody an idea ?

here is my code :

Sub main()

   
    UserForm1.Show
   
    If choix = False Then Exit Sub
   
   
    Dim swApp As SldWorks.SldWorks
    Dim swModel As SldWorks.ModelDoc2
    Dim swModelDocExt As SldWorks.ModelDocExtension
    Dim swSelMgr As SldWorks.SelectionMgr
    Dim swMotionMgr As SwMotionStudy.MotionStudyManager
    Dim swMotionStudy1 As SwMotionStudy.MotionStudy
    Dim swMotorFeat As SldWorks.SimulationMotorFeatureData
    Dim swGravityFeat As Object
    Dim boolstatus As Boolean
    Dim swFeat As SldWorks.Feature

    Set swApp = Application.SldWorks
    Set swModel = swApp.ActiveDoc
   
    Set swModelDocExt = swModel.Extension
    Set swSelMgr = swModel.SelectionManager

    ' Get the MotionManager
    Set swMotionMgr = swModelDocExt.GetMotionStudyManager()
    If (swMotionMgr Is Nothing) Then
          End

    End If

    ' Get Motion Study 1
    Set swMotionStudy1 = swMotionMgr.GetMotionStudy("Etude de mouvement 1")

    ' Activation de l'onglet Etude de mouvement 1
    swMotionStudy1.Activate
   

    param = num_prem_sphere
    num_point = 0
   
    fichier_existe = True
   
    While fichier_existe = True
   
        num_sphere = num_point + param
       
        condition = False
        If type_gene = 2 And num_sphere = num_sphere_moteur Then condition = True
       
        If condition = True Or type_gene = 1 Then
       
        For j = 1 To 3

            ' Création de la fonction moteur linéair en objet data
            Set swMotorFeat = swMotionStudy1.CreateDefinition(swFmAEMLinearMotor)
   
            ' Affectation moteur déplacement interpolé
            swMotorFeat.InterpolatedMotor swSimulationMotorDrive_Displacement, 1
           
   
            ' Affectation direction
          
            If j = 1 Then boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.00200000000001, -1.108492668891E-04, -3.443181067269E-04, False, 0, Nothing, 0)
            If j = 2 Then boolstatus = swModelDocExt.SelectByID2("", "FACE", -1.583789315305E-04, 0.001999999999981, 0.000056847285407, False, 0, Nothing, 0)
            If j = 3 Then boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.000087205541206, -3.416578816768E-04, 0.001999999999953, False, 0, Nothing, 0)

           
            swMotorFeat.DirectionReference = swSelMgr.GetSelectedObject6(1, -1)
          
           
       
            ' Affectation du point d'application du moteur
            boolstatus = swModelDocExt.SelectByID2("Point1@Origine@sphère-" & num_sphere & "@Assemblage1", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
            swMotorFeat.Location = swSelMgr.GetSelectedObject6(1, -1)
   
   
            ' Affectation de l'objet de référence
            If j = 1 Then boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.00200000000001, -1.108492668891E-04, -3.443181067269E-04, False, 0, Nothing, 0)
            If j = 2 Then boolstatus = swModelDocExt.SelectByID2("", "FACE", -1.583789315305E-04, 0.001999999999981, 0.000056847285407, False, 0, Nothing, 0)
            If j = 3 Then boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.000087205541206, -3.416578816768E-04, 0.001999999999953, False, 0, Nothing, 0)
           
            Dim RelObj As SldWorks.Component2
            Set RelObj = swSelMgr.GetSelectedObjectsComponent3(1, -1)
            swMotorFeat.RelativeComponent = RelObj

            If j = 1 Then dir_dep = "x"
            If j = 2 Then dir_dep = "y"
            If j = 3 Then dir_dep = "z"
           
           
            'Chargement du fichier de données de déplacement
            chemin_fichier = "C:\Documents and Settings\pmorandi\Bureau\resu_dep\point" & num_point & "_" & dir_dep & ".txt"
            boolstatus = swMotorFeat.LoadSplineData(chemin_fichier)
           
   
            ' Print the motor type
            Debug.Print swMotorFeat.MotorType
           
   
            ' Create the linear motor feature
            Set swFeat = swMotionStudy1.CreateFeature(swMotorFeat)
           

       
            If swFeat Is Nothing Then
            Debug.Print " ERROR: Creation of the motor feature failed."
            Else
            Debug.Print "Name of the feature added : " & swFeat.Name
            End If

        Next
           
        End If
           
        num_point = num_point + 1
        chemin_fichier = "C:\Documents and Settings\pmorandi\Bureau\resu_dep\point" & num_point & "_" & dir_dep & ".txt"
           
        fichier_existe = ExistFile(chemin_fichier)
           
       
       
        Wend
   
End Sub

Something is missing to finish corectly the work ?

thanks for advance.

Goodbye !

Pierre

SolidworksApi macros