6
$\begingroup$

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'.

$\endgroup$
5
$\begingroup$

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:

enter image description here

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

|improve this answer|||||
$\endgroup$
  • $\begingroup$ 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". $\endgroup$ – Mutant Bob Apr 10 '15 at 15:52
  • $\begingroup$ Could update this answer in that scn can be passed as self for scene drivers. $\endgroup$ – batFINGER Aug 7 '17 at 11:05
1
$\begingroup$

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

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ This will point to a specific scene..If you run this driver in different scene it will still point to 'Scene'.. $\endgroup$ – Jaroslav Jerryno Novotny Apr 11 '15 at 11:06
  • $\begingroup$ I believe this is what the OP asked for. $\endgroup$ – wardrums Apr 12 '15 at 12:38
  • $\begingroup$ 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. $\endgroup$ – Mutant Bob Apr 12 '15 at 15:20
1
$\begingroup$

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

|improve this answer|||||
$\endgroup$
  • 2
    $\begingroup$ 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 $\endgroup$ – TARDIS Maker Sep 10 '16 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.