1

I would like to add a simple python code here (like when I type 1+1, it shows 2. Or like encoding some text or whatever). Is it possible? enter image description here

user2824371
  • 796
  • 1
  • 7
  • 27

1 Answers1

4

You can't :-(

Typically, you can right-click any field and choose "Add Driver" or just type an expression with a hashtag in front, but here the hashtag is just being displayed and there's no driver related options in the context menu. Trying that from the script doesn't work either:

>>> car = bpy.data.scenes["Scene"].sequence_editor.sequences_all["Text"]
>>> curve = car.driver_add("text")
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: bpy_struct.driver_add(): property "text" not animatable

But... :-)

Someone like Will Chen would probably hack his way through this problem using a driver that updates this field as a side-effect, something like setting the Size to #[40,setattr(bpy.data.scenes["Scene"].sequence_editor.sequences_all["Text"], "text", str(frame))][0] -where the # is there only if you input the script for the first time (when the field is not purple) to tell Blender to turn it to a driver, and 40 at the very beginning is the actual size - the rest is the nasty hack to update your text to current frame.

Perhaps a more elegant solution is to run a script like so:

import bpy

def frame_change_post_text_update(scene): scene.sequence_editor.sequences_all["Text"].text = str(scene.frame_current)

name = frame_change_post_text_update.name listeners = bpy.app.handlers.frame_change_post for l in [l for l in listeners if l.name == name]: # this is here so you can change the script and run it again without having # multiple listeners stacking - make sure the function name is unique listeners.remove(l) listeners.append(frame_change_post_text_update)

Markus von Broady
  • 36,563
  • 3
  • 30
  • 99