help make this script work for any active object

I’d like this to work for any active object instead of a particular one.

I’ve tried changing “Cube” to
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()

# initialise data
data["CubeLoc"] ="Cube").location.copy()

Thanks to anyone who can make this work.

nvm, once again. Ill figure it out myself. Thanks.


cube = bpy.context.active_object

I believe that should work for the active object