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?

- 796
- 1
- 7
- 27
-
AFAIK it is not possible – Chris Jul 03 '21 at 11:41
-
1Related https://blender.stackexchange.com/questions/184906/what-is-it-called-when-you-type-math-directly-into-a-property – batFINGER Jul 03 '21 at 12:23
-
@batFINGER Well, that answers my question. Thank you, – user2824371 Jul 03 '21 at 13:02
1 Answers
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)
- 36,563
- 3
- 30
- 99
-
2Can use
if handler.__name__ == "your_listener_method":to remove specific handler methods. What you have changed to could be replaced withhandlers.frame_change_post.clear()Re-opened. – batFINGER Jul 03 '21 at 13:45 -
1