[Bf-python] Python Constraints

J L aligorith at hotmail.com
Fri Jun 30 14:08:47 CEST 2006


Hi,

Just subscribed to this list. I've got experience in python coding, and my c 
knowledge I'm picking up as I need it.

I'm currently interested in adding support for writing constraints in 
python. My main aim in this is to make it easier to create constraints 
quickly and easily, so that constraint concepts can be tested, and also so 
that constraints that help resolve specific rigging problems can be created. 
I've got the blender-side mostly sorted, but the python side I'm not sure 
how to proceed with.

COMPLEX VERSION ============================================
What I propose to do, is to:
1. let the scripter define a set of variables that blender-user can set to 
control the behaviour of the constraint. In style like Draw.Create()

2.  provide a function similar to Draw.Register(), that says what functions 
in the script should be called when evaluating the constraint, or drawing 
its settings. This should only be called in
if __name__=='__main__':   blocks so that it's only executed when updating 
the script

3. to let the user set the custom settings of a constraint, a button is 
provided on the panel for this constraint. When clicked, it calls the 
function in the script that was specified by the scripter in 2 for this 
purpose. This function is responsible for setting up + drawing + handling a 
pupblock (aka clever numbut) using the api.

4. When evaluating the constraint, the script is imported as a module. Then, 
the function in the script that was specified by the scripter in 2 for this 
purpose, is called using module.function type stuff. This function should 
return a matrix suitable to apply directly (or after conversion from python 
built-in types to however they are expressed in blender) to the ob->obmat in 
the eval_constraints function in blenkernel.


There are several issues I cannot decide on:
- have a module that the user can import in the script, that provides access 
to commonly needed/available info (such as matrix of object, matrix of 
target), or just create a dict where these things are accessable from 
hardcoded variables when running the script

- how the data from the variables in the script should be stored. Currently, 
I'm thinking of just having a string that stores all the settings as a 
repr-ed dict. But then that means that there is the overhead of re-creating 
these variables so that they can be actually used, and this happens every 
time a python constraint is evaluated (grief!). What would be a better way 
that is able to be stored in blendfiles as part of the constraint's data? 
How could the registry module be used from within the api to do so if at 
all?

- Where to place all the code. BPY_interface.c seems to be the first point 
of call, then I'm not sure whether I need to edit EXPP_interface.c 
(ipo-drivers have some code in here. Don't understand why though?).  Should 
most of the api for this be lodged in the python constraint.c file?


=============================================================

In order to simplify things, I might leave out the user-defined variables 
part (for someone more experienced to do ;)  or myself when I'm more 
experienced with all this). So here is a simpler version:

Just simply provide the scripter with the matrices of the target 'object' 
and the 'object' with the constraint somewhere. When the constraint is 
evaluated, simply run the whole script.

This was my original idea, but I thought of the cases where such limits may 
not be good (such as when such a constraint might be used in quite a few 
places, with settings that differ) in which case it would be tedious and 
possibly even problematic to find a way to store and retrieve all the 
settings.

Thanks for reading,
Aligorith

_________________________________________________________________
Check out the latest video  @  http://xtra.co.nz/streaming




More information about the Bf-python mailing list