I've created a simple stopwatch (Blender 2.79, Animation Nodes 2). I have certain frame ranges I want to time. I have a list which has two elements...a start frame, and a stop frame.

Upon reaching start frame I need to zero my stopwatch by setting a math "subtract" node equal to the current frame. I can easily detect a boolean compare of start frame and current frame, but then I need to push the value into my "subtract" node. I do not see a node for "if true alter some variable in another node, else leave the variable alone".

I'm good with detecting a true/false boolean condition...I'm lost on using that condition to trigger an event to save data for future use...to push data onto a queue or stack or array which I can refer to at the end of the video. Is there an animation node I can use to trigger a write to a math node or append to a list? Will I need to figure out how to link my boolean detection of start and stop frame to a python script, followed by the python updating the math node or list?


1 Answer 1


While I think it's possible to dynamically change the values of a node with a script, I assume the better option is to use a Script node to store an ID property, e.g. in the scene. For more complex data types than single float or int values you may have to define a custom bpy.propsproperty.

A script with a boolean for the reset as input and a single float for the time as output should work.


import bpy
scene = bpy.context.scene
frame = float(scene.frame_current)

if reset:
    scene['last_reset'] = frame

time = frame - scene.get('last_reset', 0.0)

N.B.: Interestingly, the ID property is only retained if the frame is manually converted to a float. If the float conversion is removed (frame = scene.current_frame), the property vanishes every time the reset flag is cleared.

  • $\begingroup$ This seems to be exactly what I need, but I am wondering about something. My AN script doesn't seem to allow defining a class directly in the script. Is this a restriction in the script node that it must be procedural? I was also having trouble using a module and importing that within the script, but I think that's just my lack of python knowledge. $\endgroup$
    – D. Stimits
    Jun 22, 2018 at 19:20
  • $\begingroup$ I'm not aware of any restrictions about the script. Defining a class, both within the script as well as in another module (created as additonal text file in Blender with py extension) that I imported, worked for me. Do you perhaps try to import a module that you installed for your regular Python installation. Blender uses a bundled Python version and you might have to install modules for that one separately. If there's a informative error message in the script node, that could also help to resolve the problem. $\endgroup$
    – binweg
    Jun 22, 2018 at 19:58
  • $\begingroup$ I compiled this Blender 2.79 from the Fedora 27 RPM so that I could use ffmeg. Otherwise this is configured the same as the stock 2.79. If I import sys, and then run "sys.version_info", regardless of whether I produce the script inside of blender or externally, I see "(major=3, minor=6, micro=5, releaselevel='final', serial=0)". This version of Fedora does have both python 2 and python 3, but since the script from within animation nodes says 3.6.5, I have to assume the internal Blender version is the same as 3.6.5. However, this could be a bad assumption on my part. $\endgroup$
    – D. Stimits
    Jun 23, 2018 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .