Capturing a Value as a Machine Passes

In this case, an asset named Machine with a speed and a position property is moving up and down a fixed path.

We want to capture the speed of the machine with 1m resolution along that path.

This solution exploits the fact that a calculation that returns None doesn't actually update - it continues to hold the previous value.

def CaptureSpeed(pos,offset,speed):
    if int(pos) == offset:
        return speed
    return None
 
@mdl.part("Machine Speed Over Travel",host)
def TravelSpeedCapture(mod):
 
    Position = mod.AddInput("Machine Position",7,"Machine.Position")
    Places = mod.AddInput("Maximum Position",170,"Machine.Max Position")
 
    Speed = mod.AddInput("Machine Speed",0,"Machine.Speed")
 
    for x in range(0,int(float(Places))):
        mod.AddOutput("Position " + str(x+1) + " Pass Speed",lambda x=x: CaptureSpeed(float(Position),x,float(Speed)),[Position,Speed])