I found that code that I changed a tiny bit from Batfinger I think. But I’m not sure about the scene_update_pre, I’m wondering if there would not be a better way.
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.scene_update_pre.append(loc_change)
# initialise data
data["CubeLoc"] = bpy.data.objects.get("Cube").location.copy()