I'm trying to convert the following expression for use in a driver expression:

1 if ( bpy.context.scene.frame_current == bpy.context.scene.frame_end ) else 0

So there's the "Give a man a fish" answer that expresses how to tell you're on the final frame of a render, and then there's the "Teach a man to fish" answer that more generally helps myself and everyone who follows learn how to make drivers work. But at this point I'll take whatever assistance a kind soul cares to render!

  • $\begingroup$ The code snippet works when pasted into the driver expression. Can you make your question clearer? $\endgroup$
    – Leander
    Dec 5, 2019 at 20:58
  • $\begingroup$ @Leander - My mistake: Python scripts were not permitted to run -- I had forgotten that was an issue until I reopened the file and Blender prompted me to permit execution of Python scripts. Thank you for helping. If you would like the credit points, suggest the step I forgot to take as your answer and I'll accept it! $\endgroup$
    – tobinjim
    Dec 5, 2019 at 21:16
  • $\begingroup$ Sure, thanks. I added an answer, feel free to expand it. $\endgroup$
    – Leander
    Dec 5, 2019 at 21:49

1 Answer 1


You can use a single line python expression as a driver, like an if-else statement.

1 if (bpy.context.scene.frame_current  == 1) else 0

The reason this fails, would be if python scripts have been disabled. You get this dialog after entering a python expression when python scripts are disabled. Click on "Allow Execution".

auto run dialog

If you dismissed the dialog, enable Auto Run Python Scripts in the User Preferences under Save & Load.


  • $\begingroup$ frame in the driver namespace is bpy.context.scene.frame_current Will avoid the unexpected behaviour warning message... . The expression could be 1 if frame == 1 else 0 ore even frame == 1 will return 1 and 0 for True and False.. For others eg context.scene.frame_end it is recommend that variables are used to assist building the depsgraph. $\endgroup$
    – batFINGER
    Dec 8, 2019 at 14:13

You must log in to answer this question.

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