[Bf-committers] bpy callback patch (replace scriptlink like functionality from 2.4x)

Campbell Barton ideasman42 at gmail.com
Fri Jun 24 15:27:24 CEST 2011


This is something thats been requested to be brought back from 2.4x
for quite a while,
however I wasn't that happy with scriptlinks having to be setup per
datablock, then scanning every datablock on frame change to see if any
have frame change scriptlinks for example - not too efficient and
cumbersome to manage scripts attached to each datablock.

The method I'm proposing is to have scripts register functions with an
event, example.

def func(context, scene): print("Render", scene)
bpy.app.callbacks.render_post.append(func)

This way text's with 'Register' enabled can setup the event handlers
when loading the file.

There are are of course cases where you might want to have a callbacks
associated with a specific datablock which this method doesn't deal
with.
instead you'd need to filter the data you want to operate on within
the callback - IMHO its just a trade-off between the 2 methods.

Heres the patch which has some more details, only render and load
pre/post callbacks are done.
I'll add more if this general method is acceptable.

http://projects.blender.org/tracker/index.php?func=detail&aid=27752&group_id=9&atid=127

-- 
- Campbell


More information about the Bf-committers mailing list