In the compositor I would like to add a driver to the Switch Node. I want to watch a frame value from a VSE strip.
When the current frame count equals the Strip start frame I want to switch the node.

Here is an example of what I hope to achieve:

  • When current frame is less than abs(var)+var_001 then pass no picture,

  • if current frame is greater than abs(var)+var_001 then switch source through.

Of course what I have entered is unformatted nonsense. And the switch node expects to return a true or false, not a value.

*nb: abs(var) changes negative number to integer.

Example switch driver concept

Can I define the abs(var)+var_001 (it is the VSE strip trimmed start time) as a function of some sort to call elsewhere? It's a pain to define it all the time.

  • 1
    $\begingroup$ abs(var) doesn't change a value into an integer value (which are only natural numbers), but gives their absolute value, which is the same like multiplying by -1 if negative or in other words removing the negative sign if applicably. $\endgroup$
    – Samoth
    Mar 3, 2016 at 13:03
  • 1
    $\begingroup$ Oh and the "trimmed start time" of a Strip is probably already available to you via its frame_final_start attribute. $\endgroup$
    – Samoth
    Mar 3, 2016 at 13:50
  • $\begingroup$ Thanks for the tip, I was only grabbing paths from the variables exposed in the Strip Properties, I never thought to use any of the other properties. $\endgroup$
    – 3pointedit
    Mar 6, 2016 at 22:18
  • 1
    $\begingroup$ To find out, which attributes exist from a given Property, just copy the Path like bpy.data.scenes['Scene'].sequence_editor.sequences_all[0]. including the following . into a Python Console Editor view and hit Ctrl + Space. The autocompletion feature will suggest you all available ones. $\endgroup$
    – Samoth
    Mar 7, 2016 at 10:03
  • $\begingroup$ Is there something you're still missing in my answer below? $\endgroup$
    – Samoth
    Mar 7, 2016 at 22:19

1 Answer 1


It works for me with the plain Expr: abs(var) < frame. So basically you just need a Boolean expression (omit the if in your expression) for it to drive the Switch. Basically any numerical result below 1.0 will result in Off and starting from 1.0 and above will result in On.

You can put something like (abs(var) < frame) and (abs(var) + var_001 > frame) into the box to evaluate only True during the duration of your Strip after you changed your var_001 to the frame_final_duration.

Furthermore you could Copy'n'Paste drivers if you want to use them again.

When you want to use your own function to add more complicated stuff like conditional expressions, stick to the Example code in the documentation about the Driver Namespace:

This script will add a function to the driver namespace, which can then be used in the expression driver_func(frame):

import bpy

def driver_func(val):
    return val * val    # return val squared

# add function to driver_namespace
bpy.app.driver_namespace['driver_func'] = driver_func

But giving your variables meaningful names as soon as possible is a good practise... ;-)

  • 2
    $\begingroup$ Can also use 1 if (expr) else 0 .. unnecessary for booleans handy for returning other values, eg 10 if(var > frame) else 99 $\endgroup$
    – batFINGER
    Mar 3, 2016 at 13:36
  • $\begingroup$ Kind of... I updated the answer, you need to use a function for this. Don't forget to upvote ;-) $\endgroup$
    – Samoth
    Mar 3, 2016 at 13:52
  • $\begingroup$ Can I define a name for variables in the driver window to use on other drivers? I thought you could only do that in text editor as a script. EDIT: oh i see so I define name via script which i can use in the driver entry $\endgroup$
    – 3pointedit
    Mar 5, 2016 at 1:18
  • 1
    $\begingroup$ See what you mean, it either works as you say or throws an error TypeError: bpy_struct: item.attr = val: SomeObjectType.some_bool_prop expected True/False or 0/1, not float Think I'll stick with using 0/1 or True/False for on / off. $\endgroup$
    – batFINGER
    Mar 5, 2016 at 15:18
  • 1
    $\begingroup$ Ummm, thanks... thats me! I made the video after all of the help that I got here. Thanks everyone :D $\endgroup$
    – 3pointedit
    Mar 20, 2016 at 13:22

You must log in to answer this question.

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