I think it comes from there as well, but I don't see anything abnormal in the selection of faces.
I'm thinking more about the CreateDefinition line for the linear engine
@PL.: Even if you select an object before launching the macro, it doesn't want to.
Here's the macro that works:
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swModelDocExt As SldWorks.ModelDocExtension
Sun swSelMgr As SldWorks.SelectionMgr
Sun 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
'---------
'Front Pallet
boolstatus = Part.Extension.SelectByID2("", "FACE", 0.116975825107659, 9.86277918692053E-02, -2.07497793580842E-02, False, 0, Nothing, 0)
Pallet origin
boolstatus = Part.Extension.SelectByID2("Point1@Origine@Part 1-2@toto-2", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
Origin
boolstatus = Part.Extension.SelectByID2("Point1@Origine", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
'-------------------
' Get the MotionManager
Set swMotionMgr = swModelDocExt.GetMotionStudyManager()
If (swMotionMgr Is Nothing) Then
End
End If
' Get Motion Study 1
Set swMotionStudy1 = swMotionMgr.GetMotionStudy("Motion Study 3")
' Enabling the Motion Study Tab 1
swMotionStudy1.Activate
' Creating the linear motor function as a data object
Set swMotorFeat = swMotionStudy1.CreateDefinition(swFmAEMLinearMotor)
' Interpolated displacement motor assignment
swMotorFeat.InterpolatedMotor swSimulationMotorDrive_Displacement, 0
' Management assignment
boolstatus = swModelDocExt.SelectByID2("", "FACE", 0.195285205513159, 4.90124177502054E-02, -3.98286386705422E-02, False, 0, Nothing, 0)
swMotorFeat.DirectionReference = swSelMgr.GetSelectedObject6(1, -1)
' Assigning the point of application of the engine
boolstatus = swModelDocExt.SelectByID2("Point1@Origine@Part 1-2@toto-2", "EXTSKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0)
swMotorFeat.Location = swSelMgr.GetSelectedObject6(1, -1)
' Assigning the Reference Object
boolstatus = swModelDocExt.SelectByID2("Part 1-1@toto-2", "COMPONENT", 0, 0, 0, False, 0, Nothing, 0)
Dim RelObj As SldWorks.Component2
Set RelObj = swSelMgr.GetSelectedObjectsComponent3(1, -1)
swMotorFeat.RelativeComponent = RelObj
'Loading the displacement data file
boolstatus = swMotorFeat.LoadSplineData("C:\CoordMX1.txt")
' 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
End Sub
Thanks for the help in making it work