Change another object when the length of a curve changes?

Some kind of way I need to be able to update another object whenever the length of a curve changes (in edit mode by moving the curve’s control points)

I can get the length of the curved updated in real time in a panel, but I can’t seem to translate that into affecting other objects. Does anyone know how to do this?

Well… the easiest way would be to use the dependency graph.

bpy.app.handlers.depsgraph_update_post.append(<function>)

This will update whenever anything is changed, but you can pretty easily pull the current curve length from that.

from bpy.app.handlers import persistent
@persistent
def do_things_with_curve_length(dummy):
    curve_length = <curve length>
    <do something>
bpy.app.handlers.depsgraph_update_post.append(do_things_with_curve_length)

Thanks. This looks promising, but I cannot figure out how to get the active curve object into that function (do_things_with_curve_length). This is what I tried, but it tells me “Scene” has no attribute ‘object’

from bpy.app.handlers import persistent

def do_things_with_curve_length(context):
    if context.object is not None and context.object.type == 'CURVE':
        print(context.object.name)    
   
bpy.app.handlers.depsgraph_update_post.append(do_things_with_curve_length)

I got it! I just needed to start with bpy. Thanks!!!

from bpy.app.handlers import persistent

@persistent
def do_things_with_curve_length(scene):
    obj = bpy.context.object
    if obj is not None and obj.type == 'CURVE':
        print(bpy.data.curves[obj.data.name].splines[0].calc_length())    
   
bpy.app.handlers.depsgraph_update_post.append(do_things_with_curve_length)