How can a blender driver python script access scene properties like FPS?

I would like to be able to access properties of the current scene such as render.fps, frame_start, and frame_end from within a python driver script. I have some data that is defined in terms of seconds, and I'd like the drivers consuming that data to work in two different scenes which have different frame rates.

edit: I tried using bpy.context.scene, but it turns out that is often wrong. Let me be specific: The driver is being evaluated to calculate the position of an object in scene "cave" and bpy.context.scene refers to scene "splash" . In a 1-scene .blend bpy.context.scene works fine. In a multi-scene .blend, bpy.context is not necessarily populated with what a reasonable person would consider 'the context of the driver'.

Inside script editor define your own function and register it for driver use:

import bpy

def driver_fce():
scn = bpy.context.scene
# You can use here:
scn.frame_current
scn.frame_start
scn.frame_end
scn.render.fps
# etc..

return 0    # some value

# Register it to driver namespace under name 'driver_fce':
bpy.app.driver_namespace['driver_fce'] = driver_fce


Use it like this:

Note that such drivers on node properties do not update correctly and its better to use frame change callback handler instead in that case.

• I was originally using that technique in my driver, but when I added more scenes to the .blend file, the driver started malfunctioning because bpy.context.scene referred to a different scene. I eventually determined that bpy.context is NOT what a reasonable person would call "the context of the driver". – Mutant Bob Apr 10 '15 at 15:52
• Could update this answer in that scn can be passed as self for scene drivers. – batFINGER Aug 7 '17 at 11:05

You can do this by setting the Variable type to Single Property, and the prop type to Scene. As ive done in this image.

If you want to do it in the python you can address the scene directly, rather than using context.

eg;

bpy.data.scenes['Scene'].render.fps


• This will point to a specific scene..If you run this driver in different scene it will still point to 'Scene'.. – Jaroslav Jerryno Novotny Apr 11 '15 at 11:06
• I believe this is what the OP asked for. – wardrums Apr 12 '15 at 12:38
• I want the driver to adapt to the properties of the scene it is in. If I evaluate the driver in the 60Hz scene, I need scene.render.fps==60. If I evaluate the driver in the 25Hz scene, I need scene.render.fps==25. – Mutant Bob Apr 12 '15 at 15:20

you can find most of those information in the outliner, in the data-block, you just need to search a little bit section

• This doesn't really address the question. While it does have a bit to do with it, it would be appreciated if you would flesh out your answer to explain a bit more about how you would apply the things that you have suggested. Thanks – TARDIS Maker Sep 10 '16 at 7:33