I tried the code below.
sim.NumberOfTimeSteps is 50, so the loop runs 50 times. But oCalculatedStep does not change (is always the value 51). And after running and checking the graph, the Force does not change (not set to 0 after 19 simulation steps).
What am I doing wrong?
The documentations says that ComputeSimulation will run the simulation steps from currentTimeStep to the given parameter. So this should work, right?
' Get the simulation manager from the assembly.
Dim simManager As SimulationManager
Set simManager = asmDoc.ComponentDefinition.SimulationManager
' Get the first simulation. Currently there is only ever one.
Dim sim As DynamicSimulation
Set sim = simManager.DynamicSimulations.Item(1)
' Get the force variable
Dim joint As DSJoint
Set joint = sim.DSJoints.Item(1)
Dim value As DSValue
Set value = joint.Definition.DegreesOfFreedom.Item(1).LoadForce
' Calculate the simulation
Dim step As Integer
Dim oCalculatedStep As Integer
oCalculatedStep = sim.LastComputedTimeStep
For step = 2 To sim.NumberOfTimeSteps
sim.CurrentTimeStep = step-1
sim.ComputeSimulation (step)
oCalculatedStep = sim.LastComputedTimeStep
If step >= 20 Then
value.ConstantValue = 0
End If
Next
sim.PlaySimulation