I am new to scripting in Blender and I am having trouble attaching an app handler to keyframe changes during an animation.
Below is my Python code:
import bpy
def my_handler():
bpy.data.objects["Cube"].location[0] += 0.5
bpy.app.handlers.frame_change_pre.append(my_handler)
I tried to call my_handler
, which moves an object when the frame changes, manually or when the animation starts.
I have written the code in text editor. After I run script, nothing really happens. Please help me someone out there I couldn't find anything online.
def handler(scene):
cube = scene.objects.get("Cube")
will be the object if it is in the scene, None otherwise. Without this the object will move when changing frame on any scene. Also recommend something likecube.location.x = scene.frame_current * 0.5
to stop the object moving collectively further away every frame change. (or reset at a certain frame) $\endgroup$ – batFINGER Nov 18 '18 at 10:41