I’d like this to work for any active object instead of a particular one.
I’ve tried changing “Cube” to bpy.context.active_object.name
but nothing…
import bpy
data = {} #keep data in a dictionary
TOL = 1.0e-4 #how much the cube needs to move in a frame
def loc_change(scene):
# run some scripts if the cube has moved.
cube = scene.objects.get("Cube")
loc = cube.location
dloc = loc - data["CubeLoc"]
if dloc.length > TOL:
print("FRAME:%d Cube has moved" % scene.frame_current)
data["CubeLoc"] = loc.copy()
bpy.app.handlers.frame_change_pre.append(loc_change)
# initialise data
data["CubeLoc"] = bpy.data.objects.get("Cube").location.copy()
Thanks to anyone who can make this work.