== Clamp To Constraint ==
[blender.git] / source / blender / python / api2_2x / Constraint.c
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * This is a new part of Blender.
27  *
28  * Contributor(s): Joseph Gilbert, Ken Hughes, Joshua Leung
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include "Constraint.h" /*This must come first*/
34
35 #include "DNA_object_types.h"
36 #include "DNA_effect_types.h"
37 #include "DNA_vec_types.h"
38 #include "DNA_curve_types.h"
39 #include "DNA_text_types.h"
40
41 #include "BKE_main.h"
42 #include "BKE_global.h"
43 #include "BKE_library.h"
44 #include "BKE_action.h"
45 #include "BKE_armature.h"
46 #include "BKE_constraint.h"
47 #include "BLI_blenlib.h"
48 #include "BIF_editconstraint.h"
49 #include "BSE_editipo.h"
50 #include "MEM_guardedalloc.h"
51 #include "butspace.h"
52 #include "blendef.h"
53 #include "mydevice.h"
54
55 #include "IDProp.h"
56 #include "Object.h"
57 #include "NLA.h"
58 #include "Text.h"
59 #include "gen_utils.h"
60
61 enum constraint_constants {
62         EXPP_CONSTR_XROT = 0,
63         EXPP_CONSTR_YROT = 1,
64         EXPP_CONSTR_ZROT = 2,
65         EXPP_CONSTR_XSIZE = 10,
66         EXPP_CONSTR_YSIZE = 11,
67         EXPP_CONSTR_ZSIZE = 12,
68         EXPP_CONSTR_XLOC = 20,
69         EXPP_CONSTR_YLOC = 21,
70         EXPP_CONSTR_ZLOC = 22,
71
72         EXPP_CONSTR_MAXX = TRACK_X,
73         EXPP_CONSTR_MAXY = TRACK_Y,
74         EXPP_CONSTR_MAXZ = TRACK_Z,
75         EXPP_CONSTR_MINX = TRACK_nX,
76         EXPP_CONSTR_MINY = TRACK_nY,
77         EXPP_CONSTR_MINZ = TRACK_nZ,
78
79         EXPP_CONSTR_TARGET = 100,
80         EXPP_CONSTR_STRETCH,
81         EXPP_CONSTR_ITERATIONS,
82         EXPP_CONSTR_BONE,
83         EXPP_CONSTR_CHAINLEN,
84         EXPP_CONSTR_POSWEIGHT,
85         EXPP_CONSTR_ROTWEIGHT,
86         EXPP_CONSTR_ROTATE,
87         EXPP_CONSTR_USETIP,
88
89         EXPP_CONSTR_ACTION,
90         EXPP_CONSTR_START,
91         EXPP_CONSTR_END,
92         EXPP_CONSTR_MIN,
93         EXPP_CONSTR_MAX,
94         EXPP_CONSTR_KEYON,
95
96         EXPP_CONSTR_TRACK,
97         EXPP_CONSTR_UP,
98
99         EXPP_CONSTR_RESTLENGTH,
100         EXPP_CONSTR_VOLVARIATION,
101         EXPP_CONSTR_VOLUMEMODE,
102         EXPP_CONSTR_PLANE,
103
104         EXPP_CONSTR_FOLLOW,
105         EXPP_CONSTR_OFFSET,
106         EXPP_CONSTR_FORWARD,
107
108         EXPP_CONSTR_LOCK,
109
110         EXPP_CONSTR_MINMAX,
111         EXPP_CONSTR_STICKY,
112
113         EXPP_CONSTR_COPY,
114         EXPP_CONSTR_LIMIT,
115         EXPP_CONSTR_CLAMP,
116         
117         EXPP_CONSTR_LIMXMIN = LIMIT_XMIN,
118         EXPP_CONSTR_LIMXMAX = LIMIT_XMAX,
119         EXPP_CONSTR_LIMYMIN = LIMIT_YMIN,
120         EXPP_CONSTR_LIMYMAX = LIMIT_YMAX,
121         EXPP_CONSTR_LIMZMIN = LIMIT_ZMIN,
122         EXPP_CONSTR_LIMZMAX = LIMIT_ZMAX,
123         
124         EXPP_CONSTR_LIMXROT = LIMIT_XROT,
125         EXPP_CONSTR_LIMYROT = LIMIT_YROT,
126         EXPP_CONSTR_LIMZROT = LIMIT_ZROT,
127         
128         EXPP_CONSTR_CLAMPCYCLIC,
129         
130         EXPP_CONSTR_XMIN,
131         EXPP_CONSTR_XMAX,
132         EXPP_CONSTR_YMIN,
133         EXPP_CONSTR_YMAX,
134         EXPP_CONSTR_ZMIN,
135         EXPP_CONSTR_ZMAX,
136         
137         EXPP_CONSTR_SCRIPT,
138         EXPP_CONSTR_PROPS,
139         
140         EXPP_CONSTR_FROM,
141         EXPP_CONSTR_TO,
142         EXPP_CONSTR_EXPO,
143         EXPP_CONSTR_FROMMINX,
144         EXPP_CONSTR_FROMMAXX,
145         EXPP_CONSTR_FROMMINY,
146         EXPP_CONSTR_FROMMAXY,
147         EXPP_CONSTR_FROMMINZ,
148         EXPP_CONSTR_FROMMAXZ,
149         EXPP_CONSTR_TOMINX,
150         EXPP_CONSTR_TOMAXX,
151         EXPP_CONSTR_TOMINY,
152         EXPP_CONSTR_TOMAXY,
153         EXPP_CONSTR_TOMINZ,
154         EXPP_CONSTR_TOMAXZ,
155         EXPP_CONSTR_MAPX,
156         EXPP_CONSTR_MAPY,
157         EXPP_CONSTR_MAPZ,
158         
159         EXPP_CONSTR_OWNSPACE,
160         EXPP_CONSTR_TARSPACE,
161                 
162         EXPP_CONSTR_RB_TYPE,
163         EXPP_CONSTR_RB_BALL,
164         EXPP_CONSTR_RB_HINGE,
165         EXPP_CONSTR_RB_GENERIC6DOF,
166         EXPP_CONSTR_RB_VEHICLE,
167         EXPP_CONSTR_RB_PIVX,
168         EXPP_CONSTR_RB_PIVY,
169         EXPP_CONSTR_RB_PIVZ,
170         EXPP_CONSTR_RB_AXX,
171         EXPP_CONSTR_RB_AXY,
172         EXPP_CONSTR_RB_AXZ,
173         EXPP_CONSTR_RB_MINLIMIT0,
174         EXPP_CONSTR_RB_MINLIMIT1,
175         EXPP_CONSTR_RB_MINLIMIT2,
176         EXPP_CONSTR_RB_MINLIMIT3,
177         EXPP_CONSTR_RB_MINLIMIT4,
178         EXPP_CONSTR_RB_MINLIMIT5,
179         EXPP_CONSTR_RB_MAXLIMIT0,
180         EXPP_CONSTR_RB_MAXLIMIT1,
181         EXPP_CONSTR_RB_MAXLIMIT2,
182         EXPP_CONSTR_RB_MAXLIMIT3,
183         EXPP_CONSTR_RB_MAXLIMIT4,
184         EXPP_CONSTR_RB_MAXLIMIT5,
185         EXPP_CONSTR_RB_EXTRAFZ,
186         EXPP_CONSTR_RB_FLAG,
187         
188 };
189
190 /*****************************************************************************/
191 /* Python BPy_Constraint methods declarations:                               */
192 /*****************************************************************************/
193 static PyObject *Constraint_getName( BPy_Constraint * self );
194 static int Constraint_setName( BPy_Constraint * self, PyObject *arg );
195 static PyObject *Constraint_getType( BPy_Constraint * self );
196 static PyObject *Constraint_getInfluence( BPy_Constraint * self );
197 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * arg );
198
199 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg );
200
201 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key );
202 static int Constraint_setData( BPy_Constraint * self, PyObject * key, 
203                 PyObject * value );
204
205 /*****************************************************************************/
206 /* Python BPy_Constraint methods table:                                      */
207 /*****************************************************************************/
208 static PyMethodDef BPy_Constraint_methods[] = {
209         /* name, method, flags, doc */
210         {"insertKey", ( PyCFunction ) Constraint_insertKey, METH_O,
211          "Insert influence keyframe for constraint"},
212         {NULL, NULL, 0, NULL}
213 };
214
215 /*****************************************************************************/
216 /* Python BPy_Constraint attributes get/set structure:                       */
217 /*****************************************************************************/
218 static PyGetSetDef BPy_Constraint_getseters[] = {
219         {"name",
220         (getter)Constraint_getName, (setter)Constraint_setName,
221          "Constraint name", NULL},
222         {"type",
223         (getter)Constraint_getType, (setter)NULL,
224          "Constraint type (read only)", NULL},
225         {"influence",
226         (getter)Constraint_getInfluence, (setter)Constraint_setInfluence,
227          "Constraint influence", NULL},
228         {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
229 };
230
231 /*****************************************************************************/
232 /* Python Constraint_Type Mapping Methods table:                             */
233 /*****************************************************************************/
234 static PyMappingMethods Constraint_as_mapping = {
235         NULL,                               /* mp_length        */
236         ( binaryfunc ) Constraint_getData,      /* mp_subscript     */
237         ( objobjargproc ) Constraint_setData,   /* mp_ass_subscript */
238 };
239
240 /*****************************************************************************/
241 /* Python Constraint_Type callback function prototypes:                      */
242 /*****************************************************************************/
243 static PyObject *Constraint_repr( BPy_Constraint * self );
244 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b );
245
246 /*****************************************************************************/
247 /* Python Constraint_Type structure definition:                              */
248 /*****************************************************************************/
249 PyTypeObject Constraint_Type = {
250         PyObject_HEAD_INIT( NULL )  /* required py macro */
251         0,                          /* ob_size */
252         /*  For printing, in format "<module>.<name>" */
253         "Blender Constraint",         /* char *tp_name; */
254         sizeof( BPy_Constraint ),     /* int tp_basicsize; */
255         0,                          /* tp_itemsize;  For allocation */
256
257         /* Methods to implement standard operations */
258
259         NULL,                                           /* destructor tp_dealloc; */
260         NULL,                       /* printfunc tp_print; */
261         NULL,                       /* getattrfunc tp_getattr; */
262         NULL,                       /* setattrfunc tp_setattr; */
263         ( cmpfunc ) Constraint_compare, /* cmpfunc tp_compare; */
264         ( reprfunc ) Constraint_repr, /* reprfunc tp_repr; */
265
266         /* Method suites for standard classes */
267
268         NULL,                       /* PyNumberMethods *tp_as_number; */
269         NULL,                       /* PySequenceMethods *tp_as_sequence; */
270         &Constraint_as_mapping,       /* PyMappingMethods *tp_as_mapping; */
271
272         /* More standard operations (here for binary compatibility) */
273
274         NULL,                       /* hashfunc tp_hash; */
275         NULL,                       /* ternaryfunc tp_call; */
276         NULL,                       /* reprfunc tp_str; */
277         NULL,                       /* getattrofunc tp_getattro; */
278         NULL,                       /* setattrofunc tp_setattro; */
279
280         /* Functions to access object as input/output buffer */
281         NULL,                       /* PyBufferProcs *tp_as_buffer; */
282
283   /*** Flags to define presence of optional/expanded features ***/
284         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
285
286         NULL,                       /*  char *tp_doc;  Documentation string */
287   /*** Assigned meaning in release 2.0 ***/
288         /* call function for all accessible objects */
289         NULL,                       /* traverseproc tp_traverse; */
290
291         /* delete references to contained objects */
292         NULL,                       /* inquiry tp_clear; */
293
294   /***  Assigned meaning in release 2.1 ***/
295   /*** rich comparisons ***/
296         NULL,                       /* richcmpfunc tp_richcompare; */
297
298   /***  weak reference enabler ***/
299         0,                          /* long tp_weaklistoffset; */
300
301   /*** Added in release 2.2 ***/
302         /*   Iterators */
303         NULL,                       /* getiterfunc tp_iter; */
304         NULL,                       /* iternextfunc tp_iternext; */
305
306   /*** Attribute descriptor and subclassing stuff ***/
307         BPy_Constraint_methods,       /* struct PyMethodDef *tp_methods; */
308         NULL,                       /* struct PyMemberDef *tp_members; */
309         BPy_Constraint_getseters,     /* struct PyGetSetDef *tp_getset; */
310         NULL,                       /* struct _typeobject *tp_base; */
311         NULL,                       /* PyObject *tp_dict; */
312         NULL,                       /* descrgetfunc tp_descr_get; */
313         NULL,                       /* descrsetfunc tp_descr_set; */
314         0,                          /* long tp_dictoffset; */
315         NULL,                       /* initproc tp_init; */
316         NULL,                       /* allocfunc tp_alloc; */
317         NULL,                       /* newfunc tp_new; */
318         /*  Low-level free-memory routine */
319         NULL,                       /* freefunc tp_free;  */
320         /* For PyObject_IS_GC */
321         NULL,                       /* inquiry tp_is_gc;  */
322         NULL,                       /* PyObject *tp_bases; */
323         /* method resolution order */
324         NULL,                       /* PyObject *tp_mro;  */
325         NULL,                       /* PyObject *tp_cache; */
326         NULL,                       /* PyObject *tp_subclasses; */
327         NULL,                       /* PyObject *tp_weaklist; */
328         NULL
329 };
330
331 /*****************************************************************************/
332 /* Python BPy_Constraint methods:                                            */
333 /*****************************************************************************/
334
335 /*
336  * return the name of this constraint
337  */
338
339 static PyObject *Constraint_getName( BPy_Constraint * self )
340 {
341         if( !self->con )
342                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
343                                 "This constraint has been removed!" );
344         
345         return PyString_FromString( self->con->name );
346 }
347
348 /*
349  * set the name of this constraint
350  */
351
352 static int Constraint_setName( BPy_Constraint * self, PyObject * attr )
353 {
354         char *name = PyString_AsString( attr );
355         if( !name )
356                 return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
357
358         if( !self->con )
359                 return EXPP_ReturnIntError( PyExc_RuntimeError,
360                                 "This constraint has been removed!" );
361         
362         BLI_strncpy( self->con->name, name, sizeof( self->con->name ) );
363
364         return 0;
365 }
366
367 /*
368  * return the influence of this constraint
369  */
370
371 static PyObject *Constraint_getInfluence( BPy_Constraint * self )
372 {
373         if( !self->con )
374                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
375                                 "This constraint has been removed!" );
376         
377         return PyFloat_FromDouble( (double)self->con->enforce );
378 }
379
380 /*
381  * set the influence of this constraint
382  */
383
384 static int Constraint_setInfluence( BPy_Constraint * self, PyObject * value )
385 {
386         if( !self->con )
387                 return EXPP_ReturnIntError( PyExc_RuntimeError,
388                                 "This constraint has been removed!" );
389
390         return EXPP_setFloatClamped( value, &self->con->enforce, 0.0, 1.0 );
391 }
392
393 /*
394  * return the type of this constraint
395  */
396
397 static PyObject *Constraint_getType( BPy_Constraint * self )
398 {
399         if( !self->con )
400                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
401                                 "This constraint has been removed!" );
402         
403         return PyInt_FromLong( self->con->type );
404 }
405
406 /*
407  * add keyframe for influence
408         base on code in add_influence_key_to_constraint_func()
409  */
410 static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * value )
411 {
412         IpoCurve *icu;
413         float cfra = (float)PyFloat_AsDouble(value);
414         char actname[32] = "";
415         Object *ob = self->obj;
416         bConstraint *con = self->con;
417
418         if( !self->con )
419                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
420                                 "This constraint has been removed!" );
421
422         /* get frame for inserting key */
423         if( PyFloat_Check(value) )
424                 return EXPP_ReturnPyObjError( PyExc_TypeError,
425                                 "expected a float argument" );
426
427         /* constraint_active_func(ob_v, con_v); */
428         get_constraint_ipo_context( ob, actname );
429         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
430         
431         if (!icu)
432                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
433                                 "cannot get a curve from this IPO, may be using libdata" );
434         
435         if( ob->action )
436                 insert_vert_icu( icu, get_action_frame(ob, cfra), con->enforce, 0);
437         else
438                 insert_vert_icu( icu, cfra, con->enforce, 0);
439
440         Py_RETURN_NONE;
441 }
442
443 /******************************************************************************/
444 /* Constraint Space Conversion get/set procedures                                                         */
445 /*              - These are called before/instead of individual constraint                        */
446 /*                get/set procedures when OWNERSPACE or TARGETSPACE are chosen            */
447 /*              - They are only called from Constraint_g/setData                                          */
448 /******************************************************************************/
449
450 static PyObject *constspace_getter( BPy_Constraint * self, int type )
451 {
452         bConstraint *con= (bConstraint *)(self->con);
453         
454         /* depends on type being asked for
455          * NOTE: not all constraints support all space types 
456          */
457         if (type == EXPP_CONSTR_OWNSPACE) {
458                 switch (con->type) {
459                         /* all of these support this... */
460                         case CONSTRAINT_TYPE_PYTHON:
461                         case CONSTRAINT_TYPE_LOCLIKE:
462                         case CONSTRAINT_TYPE_ROTLIKE:
463                         case CONSTRAINT_TYPE_SIZELIKE:
464                         case CONSTRAINT_TYPE_TRACKTO:
465                         case CONSTRAINT_TYPE_LOCLIMIT:
466                         case CONSTRAINT_TYPE_ROTLIMIT:
467                         case CONSTRAINT_TYPE_SIZELIMIT:
468                         case CONSTRAINT_TYPE_TRANSFORM:
469                                 return PyInt_FromLong( (long)con->ownspace );
470                 }
471         }
472         else if (type == EXPP_CONSTR_TARSPACE) {
473                 switch (con->type) {
474                         /* all of these support this... */
475                         case CONSTRAINT_TYPE_PYTHON:
476                         case CONSTRAINT_TYPE_ACTION:
477                         case CONSTRAINT_TYPE_LOCLIKE:
478                         case CONSTRAINT_TYPE_ROTLIKE:
479                         case CONSTRAINT_TYPE_SIZELIKE:
480                         case CONSTRAINT_TYPE_TRACKTO:
481                         case CONSTRAINT_TYPE_TRANSFORM:
482                                 return PyInt_FromLong( (long)con->tarspace );
483                 }
484         }
485         
486         /* raise error if failed */
487         return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
488 }
489
490 static int constspace_setter( BPy_Constraint *self, int type, PyObject *value )
491 {
492         bConstraint *con= (bConstraint *)(self->con);
493         
494         /* depends on type being asked for
495          * NOTE: not all constraints support all space types 
496          */
497         if (type == EXPP_CONSTR_OWNSPACE) {
498                 switch (con->type) {
499                         /* all of these support this... */
500                         case CONSTRAINT_TYPE_PYTHON:
501                         case CONSTRAINT_TYPE_LOCLIKE:
502                         case CONSTRAINT_TYPE_ROTLIKE:
503                         case CONSTRAINT_TYPE_SIZELIKE:
504                         case CONSTRAINT_TYPE_TRACKTO:
505                         case CONSTRAINT_TYPE_LOCLIMIT:
506                         case CONSTRAINT_TYPE_ROTLIMIT:
507                         case CONSTRAINT_TYPE_SIZELIMIT:
508                         case CONSTRAINT_TYPE_TRANSFORM:
509                         {
510                                 /* only copy depending on ownertype */
511                                 if (self->pchan) {
512                                         return EXPP_setIValueClamped( value, &con->ownspace, 
513                                                         CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' );
514                                 }
515                                 else {
516                                         return EXPP_setIValueClamped( value, &con->ownspace, 
517                                                         CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' );
518                                 }
519                         }
520                                 break;
521                 }
522         }
523         else if (type == EXPP_CONSTR_TARSPACE) {
524                 switch (con->type) {
525                         /* all of these support this... */
526                         case CONSTRAINT_TYPE_PYTHON:
527                         case CONSTRAINT_TYPE_ACTION:
528                         case CONSTRAINT_TYPE_LOCLIKE:
529                         case CONSTRAINT_TYPE_ROTLIKE:
530                         case CONSTRAINT_TYPE_SIZELIKE:
531                         case CONSTRAINT_TYPE_TRACKTO:
532                         case CONSTRAINT_TYPE_TRANSFORM:
533                         {
534                                 Object *tar;
535                                 char *subtarget;
536                                 
537                                 tar= get_constraint_target(con, &subtarget);
538                                 
539                                 /* only copy depending on target-type */
540                                 if (tar && subtarget[0]) {
541                                         return EXPP_setIValueClamped( value, &con->tarspace, 
542                                                         CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' );
543                                 }
544                                 else if (tar) {
545                                         return EXPP_setIValueClamped( value, &con->tarspace, 
546                                                         CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' );
547                                 }
548                         }
549                                 break;
550                 }
551         }
552         
553         /* raise error if failed */
554         return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
555 }
556
557 /*****************************************************************************/
558 /* Specific constraint get/set procedures                                    */
559 /*****************************************************************************/
560
561 static PyObject *kinematic_getter( BPy_Constraint * self, int type )
562 {
563         bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
564
565         switch( type ) {
566         case EXPP_CONSTR_TARGET:
567                 return Object_CreatePyObject( con->tar );
568         case EXPP_CONSTR_BONE:
569                 return PyString_FromString( con->subtarget );
570         case EXPP_CONSTR_STRETCH:
571                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_STRETCH ) ) ;
572         case EXPP_CONSTR_ITERATIONS:
573                 return PyInt_FromLong( (long)con->iterations );
574         case EXPP_CONSTR_CHAINLEN:
575                 return PyInt_FromLong( (long)con->rootbone );
576         case EXPP_CONSTR_POSWEIGHT:
577                 return PyFloat_FromDouble( (double)con->weight );
578         case EXPP_CONSTR_ROTWEIGHT:
579                 return PyFloat_FromDouble( (double)con->orientweight );
580         case EXPP_CONSTR_ROTATE:
581                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_ROT ) ) ;
582         case EXPP_CONSTR_USETIP:
583                 return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_TIP ) ) ;
584         default:
585                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
586         }
587 }
588
589 static int kinematic_setter( BPy_Constraint *self, int type, PyObject *value )
590 {
591         bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
592
593         switch( type ) {
594         case EXPP_CONSTR_TARGET: {
595                 Object *obj = (( BPy_Object * )value)->object;
596                 if( !BPy_Object_Check( value ) )
597                         return EXPP_ReturnIntError( PyExc_TypeError, 
598                                         "expected BPy object argument" );
599                 con->tar = obj;
600                 return 0;
601                 }
602         case EXPP_CONSTR_BONE: {
603                 char *name = PyString_AsString( value );
604                 if( !name )
605                         return EXPP_ReturnIntError( PyExc_TypeError,
606                                         "expected string arg" );
607
608                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
609
610                 return 0;
611                 }
612         case EXPP_CONSTR_STRETCH:
613                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_STRETCH, 'h' );
614         case EXPP_CONSTR_ITERATIONS:
615                 return EXPP_setIValueClamped( value, &con->iterations, 1, 10000, 'h' );
616         case EXPP_CONSTR_CHAINLEN:
617                 return EXPP_setIValueClamped( value, &con->rootbone, 0, 255, 'i' );
618         case EXPP_CONSTR_POSWEIGHT:
619                 return EXPP_setFloatClamped( value, &con->weight, 0.01f, 1.0 );
620         case EXPP_CONSTR_ROTWEIGHT:
621                 return EXPP_setFloatClamped( value, &con->orientweight, 0.01f, 1.0 );
622         case EXPP_CONSTR_ROTATE:
623                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_ROT, 'h' );
624         case EXPP_CONSTR_USETIP:
625                 return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_TIP, 'h' );
626         default:
627                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
628         }
629 }
630
631 static PyObject *action_getter( BPy_Constraint * self, int type )
632 {
633         bActionConstraint *con = (bActionConstraint *)(self->con->data);
634
635         switch( type ) {
636         case EXPP_CONSTR_TARGET:
637                 return Object_CreatePyObject( con->tar );
638         case EXPP_CONSTR_BONE:
639                 return PyString_FromString( con->subtarget );
640         case EXPP_CONSTR_ACTION:
641                 return Action_CreatePyObject( con->act );
642         case EXPP_CONSTR_START:
643                 return PyInt_FromLong( (long)con->start );
644         case EXPP_CONSTR_END:
645                 return PyInt_FromLong( (long)con->end );
646         case EXPP_CONSTR_MIN:
647                 return PyFloat_FromDouble( (double)con->min );
648         case EXPP_CONSTR_MAX:
649                 return PyFloat_FromDouble( (double)con->max );
650         case EXPP_CONSTR_KEYON:
651                 return PyInt_FromLong( (long)con->type );
652         default:
653                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
654         }
655 }
656
657 static int action_setter( BPy_Constraint *self, int type, PyObject *value )
658 {
659         bActionConstraint *con = (bActionConstraint *)(self->con->data);
660
661         switch( type ) {
662         case EXPP_CONSTR_TARGET: {
663                 Object *obj = (( BPy_Object * )value)->object;
664                 if( !BPy_Object_Check( value ) )
665                         return EXPP_ReturnIntError( PyExc_TypeError, 
666                                         "expected BPy object argument" );
667                 con->tar = obj;
668                 return 0;
669                 }
670         case EXPP_CONSTR_BONE: {
671                 char *name = PyString_AsString( value );
672                 if( !name )
673                         return EXPP_ReturnIntError( PyExc_TypeError,
674                                         "expected string arg" );
675
676                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
677
678                 return 0;
679                 }
680         case EXPP_CONSTR_ACTION: {
681                 bAction *act = (( BPy_Action * )value)->action;
682                 if( !BPy_Action_Check( value ) )
683                         return EXPP_ReturnIntError( PyExc_TypeError, 
684                                         "expected BPy action argument" );
685                 con->act = act;
686                 return 0;
687                 }
688         case EXPP_CONSTR_START:
689                 return EXPP_setIValueClamped( value, &con->start, 1, MAXFRAME, 'h' );
690         case EXPP_CONSTR_END:
691                 return EXPP_setIValueClamped( value, &con->end, 1, MAXFRAME, 'h' );
692         case EXPP_CONSTR_MIN:
693                 if (con->type < 10)
694                         return EXPP_setFloatClamped( value, &con->min, -180.0, 180.0 );
695                 else if (con->type < 20)
696                         return EXPP_setFloatClamped( value, &con->min, 0.0001, 1000.0 );
697                 else 
698                         return EXPP_setFloatClamped( value, &con->min, -1000.0, 1000.0 );
699         case EXPP_CONSTR_MAX:
700                 if (con->type < 10)
701                         return EXPP_setFloatClamped( value, &con->max, -180.0, 180.0 );
702                 else if (con->type < 20)
703                         return EXPP_setFloatClamped( value, &con->max, 0.0001, 1000.0 );
704                 else 
705                         return EXPP_setFloatClamped( value, &con->max, -1000.0, 1000.0 );
706         case EXPP_CONSTR_KEYON:
707                 return EXPP_setIValueRange( value, &con->type,
708                                 EXPP_CONSTR_XROT, EXPP_CONSTR_ZLOC, 'h' );
709         default:
710                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
711         }
712 }
713
714 static PyObject *trackto_getter( BPy_Constraint * self, int type )
715 {
716         bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
717
718         switch( type ) {
719         case EXPP_CONSTR_TARGET:
720                 return Object_CreatePyObject( con->tar );
721         case EXPP_CONSTR_BONE:
722                 return PyString_FromString( con->subtarget );
723         case EXPP_CONSTR_TRACK:
724                 return PyInt_FromLong( (long)con->reserved1 );
725         case EXPP_CONSTR_UP:
726                 return PyInt_FromLong( (long)con->reserved2 );
727         default:
728                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
729         }
730 }
731
732 static int trackto_setter( BPy_Constraint *self, int type, PyObject *value )
733 {
734         bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
735
736         switch( type ) {
737         case EXPP_CONSTR_TARGET: {
738                 Object *obj = (( BPy_Object * )value)->object;
739                 if( !BPy_Object_Check( value ) )
740                         return EXPP_ReturnIntError( PyExc_TypeError, 
741                                         "expected BPy object argument" );
742                 con->tar = obj;
743                 return 0;
744                 }
745         case EXPP_CONSTR_BONE: {
746                 char *name = PyString_AsString( value );
747                 if( !name )
748                         return EXPP_ReturnIntError( PyExc_TypeError,
749                                         "expected string arg" );
750
751                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
752
753                 return 0;
754                 }
755         case EXPP_CONSTR_TRACK:
756                 return EXPP_setIValueRange( value, &con->reserved1,
757                                 TRACK_X, TRACK_nZ, 'i' );
758         case EXPP_CONSTR_UP:
759                 return EXPP_setIValueRange( value, &con->reserved2,
760                                 UP_X, UP_Z, 'i' );
761         default:
762                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
763         }
764 }
765
766 static PyObject *stretchto_getter( BPy_Constraint * self, int type )
767 {
768         bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
769
770         switch( type ) {
771         case EXPP_CONSTR_TARGET:
772                 return Object_CreatePyObject( con->tar );
773         case EXPP_CONSTR_BONE:
774                 return PyString_FromString( con->subtarget );
775         case EXPP_CONSTR_RESTLENGTH:
776                 return PyFloat_FromDouble( (double)con->orglength );
777         case EXPP_CONSTR_VOLVARIATION:
778                 return PyFloat_FromDouble( (double)con->bulge );
779         case EXPP_CONSTR_VOLUMEMODE:
780                 return PyInt_FromLong( (long)con->volmode );
781         case EXPP_CONSTR_PLANE:
782                 return PyInt_FromLong( (long)con->plane );
783         default:
784                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
785         }
786 }
787
788 static int stretchto_setter( BPy_Constraint *self, int type, PyObject *value )
789 {
790         bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
791
792         switch( type ) {
793         case EXPP_CONSTR_TARGET: {
794                 Object *obj = (( BPy_Object * )value)->object;
795                 if( !BPy_Object_Check( value ) )
796                         return EXPP_ReturnIntError( PyExc_TypeError, 
797                                         "expected BPy object argument" );
798                 con->tar = obj;
799                 return 0;
800                 }
801         case EXPP_CONSTR_BONE: {
802                 char *name = PyString_AsString( value );
803                 if( !name )
804                         return EXPP_ReturnIntError( PyExc_TypeError,
805                                         "expected string arg" );
806
807                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
808
809                 return 0;
810                 }
811         case EXPP_CONSTR_RESTLENGTH:
812                 return EXPP_setFloatClamped( value, &con->orglength, 0.0, 100.0 );
813         case EXPP_CONSTR_VOLVARIATION:
814                 return EXPP_setFloatClamped( value, &con->bulge, 0.0, 100.0 );
815         case EXPP_CONSTR_VOLUMEMODE:
816                 return EXPP_setIValueRange( value, &con->volmode,
817                                 VOLUME_XZ, NO_VOLUME, 'h' );
818         case EXPP_CONSTR_PLANE: {
819                 int status, oldcode = con->plane;
820                 status = EXPP_setIValueRange( value, &con->plane,
821                                 PLANE_X, PLANE_Z, 'h' );
822                 if( !status && con->plane == PLANE_Y ) {
823                         con->plane = oldcode;
824                         return EXPP_ReturnIntError( PyExc_ValueError,
825                                         "value must be either PLANEX or PLANEZ" );
826                 }
827                 return status;
828                 }
829         default:
830                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
831         }
832 }
833
834 static PyObject *followpath_getter( BPy_Constraint * self, int type )
835 {
836         bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
837
838         switch( type ) {
839         case EXPP_CONSTR_TARGET:
840                 return Object_CreatePyObject( con->tar );
841         case EXPP_CONSTR_FOLLOW:
842                 return PyBool_FromLong( (long)( con->followflag & SELECT ) );
843         case EXPP_CONSTR_OFFSET:
844                 return PyFloat_FromDouble( (double)con->offset );
845         case EXPP_CONSTR_FORWARD:
846                 return PyInt_FromLong( (long)con->trackflag );
847         case EXPP_CONSTR_UP:
848                 return PyInt_FromLong( (long)con->upflag );
849         default:
850                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
851         }
852 }
853
854 static int followpath_setter( BPy_Constraint *self, int type, PyObject *value )
855 {
856         bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
857
858         switch( type ) {
859         case EXPP_CONSTR_TARGET: {
860                 Object *obj = (( BPy_Object * )value)->object;
861                 if( !BPy_Object_Check( value ) )
862                         return EXPP_ReturnIntError( PyExc_TypeError, 
863                                         "expected BPy object argument" );
864                 con->tar = obj;
865                 return 0;
866                 }
867         case EXPP_CONSTR_FOLLOW:
868                 return EXPP_setBitfield( value, &con->followflag, SELECT, 'i' );
869         case EXPP_CONSTR_OFFSET:
870                 return EXPP_setFloatClamped( value, &con->offset,
871                                 -MAXFRAMEF, MAXFRAMEF );
872         case EXPP_CONSTR_FORWARD:
873                 return EXPP_setIValueRange( value, &con->trackflag,
874                                 TRACK_X, TRACK_nZ, 'i' );
875         case EXPP_CONSTR_UP:
876                 return EXPP_setIValueRange( value, &con->upflag,
877                                 UP_X, UP_Z, 'i' );
878         default:
879                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
880         }
881 }
882
883 static PyObject *clampto_getter( BPy_Constraint * self, int type )
884 {
885         bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
886
887         switch( type ) {
888         case EXPP_CONSTR_TARGET:
889                 return Object_CreatePyObject( con->tar );
890         case EXPP_CONSTR_CLAMP:
891                 return PyInt_FromLong( (long)con->flag );
892         case EXPP_CONSTR_CLAMPCYCLIC:
893                 return PyBool_FromLong( (long)(con->flag2 & CLAMPTO_CYCLIC) );
894         default:
895                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
896         }
897 }
898
899 static int clampto_setter( BPy_Constraint *self, int type, PyObject *value )
900 {
901         bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
902
903         switch( type ) {
904         case EXPP_CONSTR_TARGET: {
905                 Object *obj = (( BPy_Object * )value)->object;
906                 if( !BPy_Object_Check( value ) )
907                         return EXPP_ReturnIntError( PyExc_TypeError, 
908                                         "expected BPy object argument" );
909                 con->tar = obj;
910                 return 0;
911                 }
912         case EXPP_CONSTR_CLAMP:
913                 return EXPP_setIValueRange( value, &con->flag,
914                                 CLAMPTO_AUTO, CLAMPTO_Z, 'i' );
915         case EXPP_CONSTR_CLAMPCYCLIC:
916                 return EXPP_setBitfield( value, &con->flag2, CLAMPTO_CYCLIC, 'i' );
917         default:
918                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
919         }
920 }
921 static PyObject *locktrack_getter( BPy_Constraint * self, int type )
922 {
923         bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
924
925         switch( type ) {
926         case EXPP_CONSTR_TARGET:
927                 return Object_CreatePyObject( con->tar );
928         case EXPP_CONSTR_BONE:
929                 return PyString_FromString( con->subtarget );
930         case EXPP_CONSTR_TRACK:
931                 return PyInt_FromLong( (long)con->trackflag );
932         case EXPP_CONSTR_LOCK:
933                 return PyInt_FromLong( (long)con->lockflag );
934         default:
935                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
936         }
937 }
938
939 static int locktrack_setter( BPy_Constraint *self, int type, PyObject *value )
940 {
941         bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
942
943         switch( type ) {
944         case EXPP_CONSTR_TARGET: {
945                 Object *obj = (( BPy_Object * )value)->object;
946                 if( !BPy_Object_Check( value ) )
947                         return EXPP_ReturnIntError( PyExc_TypeError, 
948                                         "expected BPy object argument" );
949                 con->tar = obj;
950                 return 0;
951                 }
952         case EXPP_CONSTR_BONE: {
953                 char *name = PyString_AsString( value );
954                 if( !name )
955                         return EXPP_ReturnIntError( PyExc_TypeError,
956                                         "expected string arg" );
957
958                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
959
960                 return 0;
961                 }
962         case EXPP_CONSTR_TRACK:
963                 return EXPP_setIValueRange( value, &con->trackflag,
964                                 TRACK_X, TRACK_nZ, 'i' );
965         case EXPP_CONSTR_LOCK:
966                 return EXPP_setIValueRange( value, &con->lockflag,
967                                 LOCK_X, LOCK_Z, 'i' );
968         default:
969                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
970         }
971 }
972
973 static PyObject *floor_getter( BPy_Constraint * self, int type )
974 {
975         bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
976
977         switch( type ) {
978         case EXPP_CONSTR_TARGET:
979                 return Object_CreatePyObject( con->tar );
980         case EXPP_CONSTR_BONE:
981                 return PyString_FromString( con->subtarget );
982         case EXPP_CONSTR_MINMAX:
983                 return PyInt_FromLong( (long)con->minmaxflag );
984         case EXPP_CONSTR_OFFSET:
985                 return PyFloat_FromDouble( (double)con->offset );
986         case EXPP_CONSTR_STICKY:
987                 return PyBool_FromLong( (long)( con->flag & MINMAX_STICKY ) ) ;
988         default:
989                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
990         }
991 }
992
993 static int floor_setter( BPy_Constraint *self, int type, PyObject *value )
994 {
995         bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
996
997         switch( type ) {
998         case EXPP_CONSTR_TARGET: {
999                 Object *obj = (( BPy_Object * )value)->object;
1000                 if( !BPy_Object_Check( value ) )
1001                         return EXPP_ReturnIntError( PyExc_TypeError, 
1002                                         "expected BPy object argument" );
1003                 con->tar = obj;
1004                 return 0;
1005                 }
1006         case EXPP_CONSTR_BONE: {
1007                 char *name = PyString_AsString( value );
1008                 if( !name )
1009                         return EXPP_ReturnIntError( PyExc_TypeError,
1010                                         "expected string arg" );
1011
1012                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1013
1014                 return 0;
1015                 }
1016         case EXPP_CONSTR_MINMAX:
1017                 return EXPP_setIValueRange( value, &con->minmaxflag,
1018                                 EXPP_CONSTR_MAXX, EXPP_CONSTR_MINZ, 'i' );
1019         case EXPP_CONSTR_OFFSET:
1020                 return EXPP_setFloatClamped( value, &con->offset, -100.0, 100.0 );
1021         case EXPP_CONSTR_STICKY:
1022                 return EXPP_setBitfield( value, &con->flag, MINMAX_STICKY, 'h' );
1023         default:
1024                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1025         }
1026 }
1027
1028 static PyObject *locatelike_getter( BPy_Constraint * self, int type )
1029 {
1030         bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
1031
1032         switch( type ) {
1033         case EXPP_CONSTR_TARGET:
1034                 return Object_CreatePyObject( con->tar );
1035         case EXPP_CONSTR_BONE:
1036                 return PyString_FromString( con->subtarget );
1037         case EXPP_CONSTR_COPY:
1038                 return PyInt_FromLong( (long)con->flag );
1039         default:
1040                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1041         }
1042 }
1043
1044 static int locatelike_setter( BPy_Constraint *self, int type, PyObject *value )
1045 {
1046         bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
1047
1048         switch( type ) {
1049         case EXPP_CONSTR_TARGET: {
1050                 Object *obj = (( BPy_Object * )value)->object;
1051                 if( !BPy_Object_Check( value ) )
1052                         return EXPP_ReturnIntError( PyExc_TypeError, 
1053                                         "expected BPy object argument" );
1054                 con->tar = obj;
1055                 return 0;
1056                 }
1057         case EXPP_CONSTR_BONE: {
1058                 char *name = PyString_AsString( value );
1059                 if( !name )
1060                         return EXPP_ReturnIntError( PyExc_TypeError,
1061                                         "expected string arg" );
1062
1063                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1064
1065                 return 0;
1066                 }
1067         case EXPP_CONSTR_COPY:
1068                 return EXPP_setIValueRange( value, &con->flag,
1069                                 0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z | LOCLIKE_X_INVERT | LOCLIKE_Y_INVERT | LOCLIKE_Z_INVERT, 'i' );
1070         default:
1071                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1072         }
1073 }
1074
1075 static PyObject *rotatelike_getter( BPy_Constraint * self, int type )
1076 {
1077         bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
1078
1079         switch( type ) {
1080         case EXPP_CONSTR_TARGET:
1081                 return Object_CreatePyObject( con->tar );
1082         case EXPP_CONSTR_BONE:
1083                 return PyString_FromString( con->subtarget );
1084         case EXPP_CONSTR_COPY:
1085                 return PyInt_FromLong( (long)con->flag );
1086         default:
1087                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1088         }
1089 }
1090
1091 static int rotatelike_setter( BPy_Constraint *self, int type, PyObject *value )
1092 {
1093         bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
1094
1095         switch( type ) {
1096         case EXPP_CONSTR_TARGET: {
1097                 Object *obj = (( BPy_Object * )value)->object;
1098                 if( !BPy_Object_Check( value ) )
1099                         return EXPP_ReturnIntError( PyExc_TypeError, 
1100                                         "expected BPy object argument" );
1101                 con->tar = obj;
1102                 return 0;
1103                 }
1104         case EXPP_CONSTR_BONE: {
1105                 char *name = PyString_AsString( value );
1106                 if( !name )
1107                         return EXPP_ReturnIntError( PyExc_TypeError,
1108                                         "expected string arg" );
1109
1110                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1111
1112                 return 0;
1113                 }
1114         case EXPP_CONSTR_COPY:
1115                 return EXPP_setIValueRange( value, &con->flag,
1116                                 0, ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z | ROTLIKE_X_INVERT | ROTLIKE_Y_INVERT | ROTLIKE_Z_INVERT, 'i' );
1117         default:
1118                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1119         }
1120 }
1121
1122 static PyObject *sizelike_getter( BPy_Constraint * self, int type )
1123 {
1124         bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1125
1126         switch( type ) {
1127         case EXPP_CONSTR_TARGET:
1128                 return Object_CreatePyObject( con->tar );
1129         case EXPP_CONSTR_BONE:
1130                 return PyString_FromString( con->subtarget );
1131         case EXPP_CONSTR_COPY:
1132                 return PyInt_FromLong( (long)con->flag );
1133         default:
1134                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1135         }
1136 }
1137
1138 static int sizelike_setter( BPy_Constraint *self, int type, PyObject *value )
1139 {
1140         bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1141
1142         switch( type ) {
1143         case EXPP_CONSTR_TARGET: {
1144                 Object *obj = (( BPy_Object * )value)->object;
1145                 if( !BPy_Object_Check( value ) )
1146                         return EXPP_ReturnIntError( PyExc_TypeError, 
1147                                         "expected BPy object argument" );
1148                 con->tar = obj;
1149                 return 0;
1150                 }
1151         case EXPP_CONSTR_BONE: {
1152                 char *name = PyString_AsString( value );
1153                 if( !name )
1154                         return EXPP_ReturnIntError( PyExc_TypeError,
1155                                         "expected string arg" );
1156
1157                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1158
1159                 return 0;
1160                 }
1161         case EXPP_CONSTR_COPY:
1162                 return EXPP_setIValueRange( value, &con->flag,
1163                                 0, SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z, 'i' );
1164         default:
1165                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1166         }
1167 }
1168
1169 static PyObject *loclimit_getter( BPy_Constraint * self, int type)
1170 {
1171         bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1172
1173         switch( type ) {
1174         case EXPP_CONSTR_LIMIT:
1175                 return PyInt_FromLong( (long)con->flag );
1176         case EXPP_CONSTR_XMIN:
1177                 return PyFloat_FromDouble( (double)con->xmin );
1178         case EXPP_CONSTR_XMAX:
1179                 return PyFloat_FromDouble( (double)con->xmax );
1180         case EXPP_CONSTR_YMIN:
1181                 return PyFloat_FromDouble( (double)con->ymin );
1182         case EXPP_CONSTR_YMAX:
1183                 return PyFloat_FromDouble( (double)con->ymax );
1184         case EXPP_CONSTR_ZMIN:
1185                 return PyFloat_FromDouble( (double)con->zmin );
1186         case EXPP_CONSTR_ZMAX:
1187                 return PyFloat_FromDouble( (double)con->zmax );
1188         default:
1189                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1190         }
1191 }
1192
1193 static int loclimit_setter( BPy_Constraint *self, int type, PyObject *value )
1194 {
1195         bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);    
1196         
1197         switch( type ) {
1198         case EXPP_CONSTR_LIMIT:
1199                 return EXPP_setIValueRange( value, &con->flag, 0, 
1200                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX , 'i' );
1201         case EXPP_CONSTR_XMIN:
1202                 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1203         case EXPP_CONSTR_XMAX:
1204                 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1205         case EXPP_CONSTR_YMIN:
1206                 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1207         case EXPP_CONSTR_YMAX:
1208                 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1209         case EXPP_CONSTR_ZMIN:
1210                 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1211         case EXPP_CONSTR_ZMAX:
1212                 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1213         default:
1214                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1215         }
1216 }
1217
1218 static PyObject *rotlimit_getter( BPy_Constraint * self, int type )
1219 {
1220         bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1221
1222         switch( type ) {
1223         case EXPP_CONSTR_LIMIT:
1224                 return PyInt_FromLong( (long)con->flag );
1225         case EXPP_CONSTR_XMIN:
1226                 return PyFloat_FromDouble( (double)con->xmin );
1227         case EXPP_CONSTR_XMAX:
1228                 return PyFloat_FromDouble( (double)con->xmax );
1229         case EXPP_CONSTR_YMIN:
1230                 return PyFloat_FromDouble( (double)con->ymin );
1231         case EXPP_CONSTR_YMAX:
1232                 return PyFloat_FromDouble( (double)con->ymax );
1233         case EXPP_CONSTR_ZMIN:
1234                 return PyFloat_FromDouble( (double)con->zmin );
1235         case EXPP_CONSTR_ZMAX:
1236                 return PyFloat_FromDouble( (double)con->zmax );
1237         default:
1238                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1239         }
1240 }
1241
1242 static int rotlimit_setter( BPy_Constraint *self, int type, PyObject *value )
1243 {
1244         bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);    
1245         
1246         switch( type ) {
1247         case EXPP_CONSTR_LIMIT:
1248                 return EXPP_setIValueRange( value, &con->flag, 0, 
1249                         LIMIT_XROT | LIMIT_YROT | LIMIT_ZROT, 'i' );
1250         case EXPP_CONSTR_XMIN:
1251                 return EXPP_setFloatClamped( value, &con->xmin, -360.0, 360.0 );
1252         case EXPP_CONSTR_XMAX:
1253                 return EXPP_setFloatClamped( value, &con->xmax, -360.0, 360.0 );
1254         case EXPP_CONSTR_YMIN:
1255                 return EXPP_setFloatClamped( value, &con->ymin, -360.0, 360.0 );
1256         case EXPP_CONSTR_YMAX:
1257                 return EXPP_setFloatClamped( value, &con->ymax, -360.0, 360.0 );
1258         case EXPP_CONSTR_ZMIN:
1259                 return EXPP_setFloatClamped( value, &con->zmin, -360.0, 360.0 );
1260         case EXPP_CONSTR_ZMAX:
1261                 return EXPP_setFloatClamped( value, &con->zmax, -360.0, 360.0 );
1262         default:
1263                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1264         }
1265 }
1266
1267 static PyObject *sizelimit_getter( BPy_Constraint * self, int type)
1268 {
1269         bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1270
1271         switch( type ) {
1272         case EXPP_CONSTR_LIMIT:
1273                 return PyInt_FromLong( (long)con->flag );
1274         case EXPP_CONSTR_XMIN:
1275                 return PyFloat_FromDouble( (double)con->xmin );
1276         case EXPP_CONSTR_XMAX:
1277                 return PyFloat_FromDouble( (double)con->xmax );
1278         case EXPP_CONSTR_YMIN:
1279                 return PyFloat_FromDouble( (double)con->ymin );
1280         case EXPP_CONSTR_YMAX:
1281                 return PyFloat_FromDouble( (double)con->ymax );
1282         case EXPP_CONSTR_ZMIN:
1283                 return PyFloat_FromDouble( (double)con->zmin );
1284         case EXPP_CONSTR_ZMAX:
1285                 return PyFloat_FromDouble( (double)con->zmax );
1286         default:
1287                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1288         }
1289 }
1290
1291 static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
1292 {
1293         bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);  
1294         
1295         switch( type ) {
1296         case EXPP_CONSTR_LIMIT:
1297                 return EXPP_setIValueRange( value, &con->flag, 0, 
1298                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1299         case EXPP_CONSTR_XMIN:
1300                 return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1301         case EXPP_CONSTR_XMAX:
1302                 return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1303         case EXPP_CONSTR_YMIN:
1304                 return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1305         case EXPP_CONSTR_YMAX:
1306                 return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1307         case EXPP_CONSTR_ZMIN:
1308                 return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1309         case EXPP_CONSTR_ZMAX:
1310                 return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1311         default:
1312                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1313         }
1314 }
1315
1316 static PyObject *script_getter( BPy_Constraint * self, int type )
1317 {
1318         bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1319
1320         switch( type ) {
1321         case EXPP_CONSTR_TARGET:
1322                 return Object_CreatePyObject( con->tar );
1323         case EXPP_CONSTR_BONE:
1324                 return PyString_FromString( con->subtarget );
1325         case EXPP_CONSTR_SCRIPT:
1326                 return Text_CreatePyObject( con->text );
1327         case EXPP_CONSTR_PROPS:
1328                 return BPy_Wrap_IDProperty( NULL, con->prop, NULL);
1329         default:
1330                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1331         }
1332 }
1333
1334 static int script_setter( BPy_Constraint *self, int type, PyObject *value )
1335 {
1336         bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1337
1338         switch( type ) {
1339         case EXPP_CONSTR_TARGET: {
1340                 Object *obj = (( BPy_Object * )value)->object;
1341                 if( !BPy_Object_Check( value ) )
1342                         return EXPP_ReturnIntError( PyExc_TypeError, 
1343                                         "expected BPy object argument" );
1344                 con->tar = obj;
1345                 return 0;
1346                 }
1347         case EXPP_CONSTR_BONE: {
1348                 char *name = PyString_AsString( value );
1349                 if( !name )
1350                         return EXPP_ReturnIntError( PyExc_TypeError,
1351                                         "expected string arg" );
1352
1353                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1354
1355                 return 0;
1356                 }
1357         case EXPP_CONSTR_SCRIPT: {
1358                 Text *text = (( BPy_Text * )value)->text;
1359                 if( !BPy_Object_Check( value ) )
1360                         return EXPP_ReturnIntError( PyExc_TypeError, 
1361                                         "expected BPy text argument" );
1362                 con->text = text;
1363                 return 0;
1364                 }
1365         case EXPP_CONSTR_PROPS:
1366                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1367                                         "setting ID-Properties of PyConstraints this way is not supported" );
1368         default:
1369                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1370         }
1371 }
1372
1373
1374 static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
1375 {
1376         bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1377
1378         switch( type ) {
1379         case EXPP_CONSTR_TARGET:
1380                 return Object_CreatePyObject( con->tar );
1381         case EXPP_CONSTR_RB_PIVX:
1382                 return PyFloat_FromDouble( (double)con->pivX );
1383         case EXPP_CONSTR_RB_PIVY:
1384                 return PyFloat_FromDouble( (double)con->pivY );
1385         case EXPP_CONSTR_RB_PIVZ:
1386                 return PyFloat_FromDouble( (double)con->pivZ );
1387         case EXPP_CONSTR_RB_AXX:
1388                 return PyFloat_FromDouble( (double)con->axX );
1389         case EXPP_CONSTR_RB_AXY:
1390                 return PyFloat_FromDouble( (double)con->axY );
1391         case EXPP_CONSTR_RB_AXZ:
1392                 return PyFloat_FromDouble( (double)con->axZ );
1393         case EXPP_CONSTR_RB_MINLIMIT0:
1394                 return PyFloat_FromDouble( (double)con->minLimit[0] );
1395         case EXPP_CONSTR_RB_MINLIMIT1:
1396                 return PyFloat_FromDouble( (double)con->minLimit[1] );
1397         case EXPP_CONSTR_RB_MINLIMIT2:
1398                 return PyFloat_FromDouble( (double)con->minLimit[2] );
1399         case EXPP_CONSTR_RB_MINLIMIT3:
1400                 return PyFloat_FromDouble( (double)con->minLimit[3] );
1401         case EXPP_CONSTR_RB_MINLIMIT4:
1402                 return PyFloat_FromDouble( (double)con->minLimit[4] );
1403         case EXPP_CONSTR_RB_MINLIMIT5:
1404                 return PyFloat_FromDouble( (double)con->minLimit[5] );
1405         case EXPP_CONSTR_RB_MAXLIMIT0:
1406                 return PyFloat_FromDouble( (double)con->maxLimit[0] );
1407         case EXPP_CONSTR_RB_MAXLIMIT1:
1408                 return PyFloat_FromDouble( (double)con->maxLimit[1] );
1409         case EXPP_CONSTR_RB_MAXLIMIT2:
1410                 return PyFloat_FromDouble( (double)con->maxLimit[2] );
1411         case EXPP_CONSTR_RB_MAXLIMIT3:
1412                 return PyFloat_FromDouble( (double)con->maxLimit[3] );
1413         case EXPP_CONSTR_RB_MAXLIMIT4:
1414                 return PyFloat_FromDouble( (double)con->maxLimit[4] );
1415         case EXPP_CONSTR_RB_MAXLIMIT5:
1416                 return PyFloat_FromDouble( (double)con->maxLimit[5] );
1417         case EXPP_CONSTR_RB_EXTRAFZ:
1418                 return PyFloat_FromDouble( (double)con->extraFz );              
1419         case EXPP_CONSTR_LIMIT:
1420                 return PyInt_FromLong( (int)con->flag );
1421                 
1422         case EXPP_CONSTR_RB_TYPE:
1423                 return PyInt_FromLong( (int)con->type );
1424         default:
1425                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );        
1426         }
1427 }
1428
1429
1430 static int rigidbody_setter( BPy_Constraint *self, int type, PyObject *value )
1431 {
1432         bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);        
1433         
1434         switch( type ) {
1435         case EXPP_CONSTR_TARGET: {
1436                 Object *obj = (( BPy_Object * )value)->object;
1437                 if( !BPy_Object_Check( value ) )
1438                         return EXPP_ReturnIntError( PyExc_TypeError, 
1439                                         "expected BPy object argument" );
1440                 con->tar = obj;
1441                 return 0;
1442                 }
1443         case EXPP_CONSTR_RB_PIVX:
1444                 return EXPP_setFloatClamped( value, &con->pivX , -1000.0, 1000.0 );
1445         case EXPP_CONSTR_RB_PIVY:
1446                 return EXPP_setFloatClamped( value, &con->pivY , -1000.0, 1000.0 );
1447         case EXPP_CONSTR_RB_PIVZ:
1448                 return EXPP_setFloatClamped( value, &con->pivZ , -1000.0, 1000.0 );
1449         case EXPP_CONSTR_RB_AXX:
1450                 return EXPP_setFloatClamped( value, &con->axX , -1000.0, 1000.0 );
1451         case EXPP_CONSTR_RB_AXY:
1452                 return EXPP_setFloatClamped( value, &con->axY , -1000.0, 1000.0 );
1453         case EXPP_CONSTR_RB_AXZ:
1454                 return EXPP_setFloatClamped( value, &con->axZ , -1000.0, 1000.0 );
1455         case EXPP_CONSTR_RB_MINLIMIT0:
1456                 return EXPP_setFloatClamped( value, &con->minLimit[0] , -1000.0, 1000.0 );
1457         case EXPP_CONSTR_RB_MINLIMIT1:
1458                 return EXPP_setFloatClamped( value, &con->minLimit[1] , -1000.0, 1000.0 );
1459         case EXPP_CONSTR_RB_MINLIMIT2:
1460                 return EXPP_setFloatClamped( value, &con->minLimit[2] , -1000.0, 1000.0 );
1461         case EXPP_CONSTR_RB_MINLIMIT3:
1462                 return EXPP_setFloatClamped( value, &con->minLimit[3] , -1000.0, 1000.0 );
1463         case EXPP_CONSTR_RB_MINLIMIT4:
1464                 return EXPP_setFloatClamped( value, &con->minLimit[4] , -1000.0, 1000.0 );
1465         case EXPP_CONSTR_RB_MINLIMIT5:
1466                 return EXPP_setFloatClamped( value, &con->minLimit[5] , -1000.0, 1000.0 );
1467         case EXPP_CONSTR_RB_MAXLIMIT0:
1468                 return EXPP_setFloatClamped( value, &con->maxLimit[0] , -1000.0, 1000.0 );
1469         case EXPP_CONSTR_RB_MAXLIMIT1:
1470                 return EXPP_setFloatClamped( value, &con->maxLimit[1] , -1000.0, 1000.0 );
1471         case EXPP_CONSTR_RB_MAXLIMIT2:
1472                 return EXPP_setFloatClamped( value, &con->maxLimit[2] , -1000.0, 1000.0 );
1473         case EXPP_CONSTR_RB_MAXLIMIT3:
1474                 return EXPP_setFloatClamped( value, &con->maxLimit[3] , -1000.0, 1000.0 );
1475         case EXPP_CONSTR_RB_MAXLIMIT4:
1476                 return EXPP_setFloatClamped( value, &con->maxLimit[4] , -1000.0, 1000.0 );
1477         case EXPP_CONSTR_RB_MAXLIMIT5:
1478                 return EXPP_setFloatClamped( value, &con->maxLimit[5] , -1000.0, 1000.0 );
1479         case EXPP_CONSTR_RB_EXTRAFZ:
1480                 return EXPP_setFloatClamped( value, &con->extraFz , -1000.0, 1000.0 );                                          
1481         case EXPP_CONSTR_LIMIT:
1482                 return EXPP_setIValueRange( value, &con->flag, 0, 
1483                         LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1484         case EXPP_CONSTR_RB_TYPE:
1485                 return EXPP_setIValueRange( value, &con->type, 0, 
1486                         EXPP_CONSTR_RB_BALL | EXPP_CONSTR_RB_HINGE | EXPP_CONSTR_RB_GENERIC6DOF | EXPP_CONSTR_RB_VEHICLE, 'i' );
1487         default:
1488                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1489         }
1490 }
1491
1492 static PyObject *childof_getter( BPy_Constraint * self, int type )
1493 {
1494         bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1495
1496         switch( type ) {
1497         case EXPP_CONSTR_TARGET:
1498                 return Object_CreatePyObject( con->tar );
1499         case EXPP_CONSTR_BONE:
1500                 return PyString_FromString( con->subtarget );
1501         case EXPP_CONSTR_COPY:
1502                 return PyInt_FromLong( (long)con->flag );
1503         default:
1504                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1505         }
1506 }
1507
1508 static int childof_setter( BPy_Constraint *self, int type, PyObject *value )
1509 {
1510         bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1511
1512         switch( type ) {
1513         case EXPP_CONSTR_TARGET: {
1514                 Object *obj = (( BPy_Object * )value)->object;
1515                 if( !BPy_Object_Check( value ) )
1516                         return EXPP_ReturnIntError( PyExc_TypeError, 
1517                                         "expected BPy object argument" );
1518                 con->tar = obj;
1519                 return 0;
1520                 }
1521         case EXPP_CONSTR_BONE: {
1522                 char *name = PyString_AsString( value );
1523                 if( !name )
1524                         return EXPP_ReturnIntError( PyExc_TypeError,
1525                                         "expected string arg" );
1526
1527                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1528
1529                 return 0;
1530                 }
1531         case EXPP_CONSTR_COPY:
1532                 return EXPP_setIValueRange( value, &con->flag,
1533                                 0, CHILDOF_LOCX| CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX | CHILDOF_ROTY | CHILDOF_ROTZ |
1534                                         CHILDOF_SIZEX |CHILDOF_SIZEY| CHILDOF_SIZEZ, 'i' );
1535         default:
1536                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1537         }
1538 }
1539
1540 static PyObject *transf_getter( BPy_Constraint * self, int type )
1541 {
1542         bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1543
1544         switch( type ) {
1545         case EXPP_CONSTR_TARGET:
1546                 return Object_CreatePyObject( con->tar );
1547         case EXPP_CONSTR_BONE:
1548                 return PyString_FromString( con->subtarget );
1549         case EXPP_CONSTR_FROM:
1550                 return PyInt_FromLong( (long)con->from );
1551         case EXPP_CONSTR_TO:
1552                 return PyInt_FromLong( (long)con->to );
1553         case EXPP_CONSTR_MAPX:
1554                 return PyInt_FromLong( (long)con->map[0] );
1555         case EXPP_CONSTR_MAPY:
1556                 return PyInt_FromLong( (long)con->map[1] );
1557         case EXPP_CONSTR_MAPZ:
1558                 return PyInt_FromLong( (long)con->map[2] );
1559         case EXPP_CONSTR_FROMMINX:
1560                 return PyFloat_FromDouble( (double)con->from_min[0] );
1561         case EXPP_CONSTR_FROMMAXX:
1562                 return PyFloat_FromDouble( (double)con->from_max[0] );
1563         case EXPP_CONSTR_FROMMINY:
1564                 return PyFloat_FromDouble( (double)con->from_min[1] );
1565         case EXPP_CONSTR_FROMMAXY:
1566                 return PyFloat_FromDouble( (double)con->from_max[1] );
1567         case EXPP_CONSTR_FROMMINZ:
1568                 return PyFloat_FromDouble( (double)con->from_min[2] );
1569         case EXPP_CONSTR_FROMMAXZ:
1570                 return PyFloat_FromDouble( (double)con->from_max[2] );
1571         case EXPP_CONSTR_TOMINX:
1572                 return PyFloat_FromDouble( (double)con->to_min[0] );
1573         case EXPP_CONSTR_TOMAXX:
1574                 return PyFloat_FromDouble( (double)con->to_max[0] );
1575         case EXPP_CONSTR_TOMINY:
1576                 return PyFloat_FromDouble( (double)con->to_min[1] );
1577         case EXPP_CONSTR_TOMAXY:
1578                 return PyFloat_FromDouble( (double)con->to_max[1] );
1579         case EXPP_CONSTR_TOMINZ:
1580                 return PyFloat_FromDouble( (double)con->to_min[2] );
1581         case EXPP_CONSTR_TOMAXZ:
1582                 return PyFloat_FromDouble( (double)con->to_max[2] );
1583         case EXPP_CONSTR_EXPO:
1584                 return PyBool_FromLong( (long)con->expo );
1585         default:
1586                 return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1587         }
1588 }
1589
1590 static int transf_setter( BPy_Constraint *self, int type, PyObject *value )
1591 {
1592         bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1593         float fmin, fmax, tmin, tmax;
1594         
1595         if (con->from == 2) {
1596                 fmin = 0.0001;
1597                 fmax = 1000.0;
1598         }
1599         else if (con->from == 1) {
1600                 fmin = -360.0;
1601                 fmax = 360.0;
1602         }
1603         else {
1604                 fmin = -1000.0;
1605                 fmax = 1000.0;
1606         }
1607         
1608         if (con->to == 2) {
1609                 tmin = 0.0001;
1610                 tmax = 1000.0;
1611         }
1612         else if (con->to == 1) {
1613                 tmin = -360.0;
1614                 tmax = 360.0;
1615         }
1616         else {
1617                 tmin = -1000.0;
1618                 tmax = 1000.0;
1619         }
1620         
1621         switch( type ) {
1622         case EXPP_CONSTR_TARGET: {
1623                 Object *obj = (( BPy_Object * )value)->object;
1624                 if( !BPy_Object_Check( value ) )
1625                         return EXPP_ReturnIntError( PyExc_TypeError, 
1626                                         "expected BPy object argument" );
1627                 con->tar = obj;
1628                 return 0;
1629                 }
1630         case EXPP_CONSTR_BONE: {
1631                 char *name = PyString_AsString( value );
1632                 if( !name )
1633                         return EXPP_ReturnIntError( PyExc_TypeError,
1634                                         "expected string arg" );
1635
1636                 BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1637
1638                 return 0;
1639                 }
1640         case EXPP_CONSTR_FROM:
1641                 return EXPP_setIValueClamped( value, &con->from, 0, 3, 'h' );
1642         case EXPP_CONSTR_TO:
1643                 return EXPP_setIValueClamped( value, &con->to, 0, 3, 'h' );
1644         case EXPP_CONSTR_MAPX:
1645                 return EXPP_setIValueClamped( value, &con->map[0], 0, 3, 'h' );
1646         case EXPP_CONSTR_MAPY:
1647                 return EXPP_setIValueClamped( value, &con->map[1], 0, 3, 'h' );
1648         case EXPP_CONSTR_MAPZ:
1649                 return EXPP_setIValueClamped( value, &con->map[2], 0, 3, 'h' );
1650         case EXPP_CONSTR_FROMMINX:
1651                 return EXPP_setFloatClamped( value, &con->from_min[0], fmin, fmax );
1652         case EXPP_CONSTR_FROMMAXX:
1653                 return EXPP_setFloatClamped( value, &con->from_max[0], fmin, fmax );
1654         case EXPP_CONSTR_FROMMINY:
1655                 return EXPP_setFloatClamped( value, &con->from_min[1], fmin, fmax );
1656         case EXPP_CONSTR_FROMMAXY:
1657                 return EXPP_setFloatClamped( value, &con->from_max[1], fmin, fmax );
1658         case EXPP_CONSTR_FROMMINZ:
1659                 return EXPP_setFloatClamped( value, &con->from_min[2], fmin, fmax );
1660         case EXPP_CONSTR_FROMMAXZ:
1661                 return EXPP_setFloatClamped( value, &con->from_max[2], fmin, fmax );
1662         case EXPP_CONSTR_TOMINX:
1663                 return EXPP_setFloatClamped( value, &con->to_min[0], tmin, tmax );
1664         case EXPP_CONSTR_TOMAXX:
1665                 return EXPP_setFloatClamped( value, &con->to_max[0], tmin, tmax );
1666         case EXPP_CONSTR_TOMINY:
1667                 return EXPP_setFloatClamped( value, &con->to_min[1], tmin, tmax );
1668         case EXPP_CONSTR_TOMAXY:
1669                 return EXPP_setFloatClamped( value, &con->to_max[1], tmin, tmax );
1670         case EXPP_CONSTR_TOMINZ:
1671                 return EXPP_setFloatClamped( value, &con->to_min[2], tmin, tmax );
1672         case EXPP_CONSTR_TOMAXZ:
1673                 return EXPP_setFloatClamped( value, &con->to_max[2], tmin, tmax );
1674         case EXPP_CONSTR_EXPO:
1675                 return EXPP_setBitfield( value, &con->expo, 1, 'h' );
1676         default:
1677                 return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1678         }
1679 }
1680
1681 /*
1682  * get data from a constraint
1683  */
1684
1685 static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
1686 {
1687         int setting;
1688
1689         if( !PyInt_Check( key ) )
1690                 return EXPP_ReturnPyObjError( PyExc_TypeError,
1691                                 "expected an int arg" );
1692
1693         if( !self->con )
1694                 return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1695                                 "This constraint has been removed!" );
1696         
1697         setting = PyInt_AsLong( key );
1698         
1699         /* bypass doing settings of individual constraints, if we're just doing
1700          * constraint space access-stuff 
1701          */
1702         if ((setting==EXPP_CONSTR_OWNSPACE) || (setting==EXPP_CONSTR_TARSPACE)) {
1703                 return constspace_getter( self, setting );
1704         }
1705         switch( self->con->type ) {
1706                 case CONSTRAINT_TYPE_NULL:
1707                         Py_RETURN_NONE;
1708                 case CONSTRAINT_TYPE_TRACKTO:
1709                         return trackto_getter( self, setting );
1710                 case CONSTRAINT_TYPE_KINEMATIC:
1711                         return kinematic_getter( self, setting );
1712                 case CONSTRAINT_TYPE_FOLLOWPATH:
1713                         return followpath_getter( self, setting );
1714                 case CONSTRAINT_TYPE_ACTION:
1715                         return action_getter( self, setting );
1716                 case CONSTRAINT_TYPE_LOCKTRACK:
1717                         return locktrack_getter( self, setting );
1718                 case CONSTRAINT_TYPE_STRETCHTO:
1719                         return stretchto_getter( self, setting );
1720                 case CONSTRAINT_TYPE_MINMAX:
1721                         return floor_getter( self, setting );
1722                 case CONSTRAINT_TYPE_LOCLIKE:
1723                         return locatelike_getter( self, setting );
1724                 case CONSTRAINT_TYPE_ROTLIKE:
1725                         return rotatelike_getter( self, setting );
1726                 case CONSTRAINT_TYPE_SIZELIKE:
1727                         return sizelike_getter( self, setting );
1728                 case CONSTRAINT_TYPE_ROTLIMIT:
1729                         return rotlimit_getter( self, setting );
1730                 case CONSTRAINT_TYPE_LOCLIMIT:
1731                         return loclimit_getter( self, setting );
1732                 case CONSTRAINT_TYPE_SIZELIMIT:
1733                         return sizelimit_getter( self, setting );
1734                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1735                         return rigidbody_getter( self, setting );
1736                 case CONSTRAINT_TYPE_CLAMPTO:
1737                         return clampto_getter( self, setting );
1738                 case CONSTRAINT_TYPE_PYTHON:
1739                         return script_getter( self, setting );
1740                 case CONSTRAINT_TYPE_CHILDOF:
1741                         return childof_getter( self, setting );
1742                 case CONSTRAINT_TYPE_TRANSFORM:
1743                         return transf_getter( self, setting );
1744                 default:
1745                         return EXPP_ReturnPyObjError( PyExc_KeyError,
1746                                         "unknown constraint type" );
1747         }
1748 }
1749
1750 static int Constraint_setData( BPy_Constraint * self, PyObject * key, 
1751                 PyObject * arg )
1752 {
1753         int key_int, result;
1754
1755         if( !PyNumber_Check( key ) )
1756                 return EXPP_ReturnIntError( PyExc_TypeError,
1757                                 "expected an int arg" );
1758         if( !self->con )
1759                 return EXPP_ReturnIntError( PyExc_RuntimeError,
1760                                 "This constraint has been removed!" );
1761         
1762         key_int = PyInt_AsLong( key );
1763         
1764         /* bypass doing settings of individual constraints, if we're just doing
1765          * constraint space access-stuff 
1766          */
1767         if ((key_int==EXPP_CONSTR_OWNSPACE) || (key_int==EXPP_CONSTR_TARSPACE)) {
1768                 result = constspace_setter( self, key_int, arg );
1769         }
1770         else {
1771                 switch( self->con->type ) {
1772                 case CONSTRAINT_TYPE_KINEMATIC:
1773                         result = kinematic_setter( self, key_int, arg );
1774                         break;
1775                 case CONSTRAINT_TYPE_ACTION:
1776                         result = action_setter( self, key_int, arg );
1777                         break;
1778                 case CONSTRAINT_TYPE_TRACKTO:
1779                         result = trackto_setter( self, key_int, arg );
1780                         break;
1781                 case CONSTRAINT_TYPE_STRETCHTO:
1782                         result = stretchto_setter( self, key_int, arg );
1783                         break;
1784                 case CONSTRAINT_TYPE_FOLLOWPATH:
1785                         result = followpath_setter( self, key_int, arg );
1786                         break;
1787                 case CONSTRAINT_TYPE_LOCKTRACK:
1788                         result = locktrack_setter( self, key_int, arg );
1789                         break;
1790                 case CONSTRAINT_TYPE_MINMAX:
1791                         result = floor_setter( self, key_int, arg );
1792                         break;
1793                 case CONSTRAINT_TYPE_LOCLIKE:
1794                         result = locatelike_setter( self, key_int, arg );
1795                         break;
1796                 case CONSTRAINT_TYPE_ROTLIKE:
1797                         result = rotatelike_setter( self, key_int, arg );
1798                         break;
1799                 case CONSTRAINT_TYPE_SIZELIKE:
1800                         result = sizelike_setter( self, key_int, arg );
1801                         break;
1802                 case CONSTRAINT_TYPE_ROTLIMIT:
1803                         result = rotlimit_setter( self, key_int, arg );
1804                         break;
1805                 case CONSTRAINT_TYPE_LOCLIMIT:
1806                         result = loclimit_setter( self, key_int, arg );
1807                         break;
1808                 case CONSTRAINT_TYPE_SIZELIMIT:
1809                         result = sizelimit_setter( self, key_int, arg);
1810                         break;
1811                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1812                         result = rigidbody_setter( self, key_int, arg);
1813                         break;
1814                 case CONSTRAINT_TYPE_CLAMPTO:
1815                         result = clampto_setter( self, key_int, arg);
1816                         break;
1817                 case CONSTRAINT_TYPE_PYTHON:
1818                         result = script_setter( self, key_int, arg);
1819                         break;
1820                 case CONSTRAINT_TYPE_CHILDOF:
1821                         result = childof_setter( self, key_int, arg);
1822                         break;
1823                 case CONSTRAINT_TYPE_TRANSFORM:
1824                         result = transf_setter( self, key_int, arg);
1825                         break;
1826                 case CONSTRAINT_TYPE_NULL:
1827                         return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1828                 default:
1829                         return EXPP_ReturnIntError( PyExc_RuntimeError,
1830                                         "unsupported constraint setting" );
1831                 }
1832         }
1833         if( !result && self->pchan )
1834                 update_pose_constraint_flags( self->obj->pose );
1835         return result;
1836 }
1837
1838 /*****************************************************************************/
1839 /* Function:    Constraint_compare                                           */
1840 /* Description: This compares 2 constraint python types, == or != only.      */
1841 /*****************************************************************************/
1842 static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b )
1843 {
1844         return ( a->con == b->con ) ? 0 : -1;
1845 }
1846
1847 /*****************************************************************************/
1848 /* Function:    Constraint_repr                                              */
1849 /* Description: This is a callback function for the BPy_Constraint type. It  */
1850 /*              builds a meaningful string to represent constraint objects.  */
1851 /*****************************************************************************/
1852
1853 static PyObject *Constraint_repr( BPy_Constraint * self )
1854 {
1855         char type[32];
1856
1857         if( !self->con )
1858                 return PyString_FromString( "[Constraint - Removed]");
1859
1860         get_constraint_typestring (type,  self->con);
1861         return PyString_FromFormat( "[Constraint \"%s\", Type \"%s\"]",
1862                         self->con->name, type );
1863 }
1864
1865 /* Three Python Constraint_Type helper functions needed by the Object module: */
1866
1867 /*****************************************************************************/
1868 /* Function:    Constraint_CreatePyObject                                    */
1869 /* Description: This function will create a new BPy_Constraint from an       */
1870 /*              existing Blender constraint structure.                       */
1871 /*****************************************************************************/
1872 PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
1873                 bConstraint *con )
1874 {
1875         BPy_Constraint *pycon;
1876         pycon = ( BPy_Constraint * ) PyObject_NEW( BPy_Constraint,
1877                         &Constraint_Type );
1878         if( !pycon )
1879                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
1880                                               "couldn't create BPy_Constraint object" );
1881
1882         pycon->con = con;
1883
1884         /* one of these two will be NULL */
1885         pycon->obj = obj;       
1886         pycon->pchan = pchan;
1887         return ( PyObject * ) pycon;
1888 }
1889
1890 /*****************************************************************************/
1891 /* Function:    Constraint_FromPyObject                                      */
1892 /* Description: This function returns the Blender constraint from the given  */
1893 /*              PyObject.                                                    */
1894 /*****************************************************************************/
1895 bConstraint *Constraint_FromPyObject( BPy_Constraint * self )
1896 {
1897         return self->con;
1898 }
1899
1900 /*****************************************************************************/
1901 /* Constraint Sequence wrapper                                               */
1902 /*****************************************************************************/
1903
1904 /*
1905  * Initialize the interator
1906  */
1907
1908 static PyObject *ConstraintSeq_getIter( BPy_ConstraintSeq * self )
1909 {
1910         if( self->pchan )
1911                 self->iter = (bConstraint *)self->pchan->constraints.first;
1912         else
1913                 self->iter = (bConstraint *)self->obj->constraints.first;
1914         return EXPP_incr_ret ( (PyObject *) self );
1915 }
1916
1917 /*
1918  * Get the next Constraint
1919  */
1920
1921 static PyObject *ConstraintSeq_nextIter( BPy_ConstraintSeq * self )
1922 {
1923         bConstraint *this = self->iter;
1924         if( this ) {
1925                 self->iter = this->next;
1926                 return Constraint_CreatePyObject( self->pchan, self->obj, this );
1927         }
1928
1929         return EXPP_ReturnPyObjError( PyExc_StopIteration,
1930                         "iterator at end" );
1931 }
1932
1933 /* return the number of constraints */
1934
1935 static int ConstraintSeq_length( BPy_ConstraintSeq * self )
1936 {
1937         return BLI_countlist( self->pchan ?
1938                 &self->pchan->constraints : &self->obj->constraints );
1939 }
1940
1941 /* return a constraint */
1942
1943 static PyObject *ConstraintSeq_item( BPy_ConstraintSeq * self, int i )
1944 {
1945         bConstraint *con = NULL;
1946
1947         /* if index is negative, start counting from the end of the list */
1948         if( i < 0 )
1949                 i += ConstraintSeq_length( self );
1950
1951         /* skip through the list until we get the constraint or end of list */
1952
1953         if( self->pchan )
1954                 con = self->pchan->constraints.first;
1955         else
1956                 con = self->obj->constraints.first;
1957
1958         while( i && con ) {
1959                 --i;
1960                 con = con->next;
1961         }
1962
1963         if( con )
1964                 return Constraint_CreatePyObject( self->pchan, self->obj, con );
1965         else
1966                 return EXPP_ReturnPyObjError( PyExc_IndexError,
1967                                 "array index out of range" );
1968 }
1969
1970 /*****************************************************************************/
1971 /* Python BPy_ConstraintSeq sequence table:                                  */
1972 /*****************************************************************************/
1973 static PySequenceMethods ConstraintSeq_as_sequence = {
1974         ( inquiry ) ConstraintSeq_length,       /* sq_length */
1975         ( binaryfunc ) 0,       /* sq_concat */
1976         ( intargfunc ) 0,       /* sq_repeat */
1977         ( intargfunc ) ConstraintSeq_item,      /* sq_item */
1978         ( intintargfunc ) 0,    /* sq_slice */
1979         ( intobjargproc ) 0,    /* sq_ass_item */
1980         ( intintobjargproc ) 0, /* sq_ass_slice */
1981         ( objobjproc ) 0,       /* sq_contains */
1982         ( binaryfunc ) 0,               /* sq_inplace_concat */
1983         ( intargfunc ) 0,               /* sq_inplace_repeat */
1984 };
1985
1986 /*
1987  * helper function to check for a valid constraint argument
1988  */
1989
1990 static bConstraint *locate_constr( BPy_ConstraintSeq *self, BPy_Constraint * value )
1991 {
1992         bConstraint *con;
1993
1994         /* check that argument is a modifier */
1995         if (!BPy_Constraint_Check(value))
1996                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_TypeError,
1997                                 "expected a constraint as an argument" );
1998
1999         /* check whether constraint has been removed */
2000         if( !value->con )
2001                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_RuntimeError,
2002                                 "This constraint has been removed!" );
2003
2004         /* verify the constraint is still exists in the stack */
2005         if( self->pchan )
2006                 con = self->pchan->constraints.first;
2007         else
2008                 con = self->obj->constraints.first;
2009         while( con && con != value->con )
2010                 con = con->next;
2011
2012         /* if we didn't find it, exception */
2013         if( !con )
2014                 return (bConstraint *)EXPP_ReturnPyObjError( PyExc_AttributeError,
2015                                 "This constraint is no longer in the object's stack" );
2016
2017         return con;
2018 }
2019
2020
2021 /* create a new constraint at the end of the list */
2022
2023 static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *value )
2024 {
2025         int type = (int)PyInt_AsLong(value);
2026         bConstraint *con;
2027
2028         /* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these?
2029          * if the value is not an int it will be -1 */
2030         if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_RIGIDBODYJOINT ) 
2031                 return EXPP_ReturnPyObjError( PyExc_ValueError,
2032                                 "arg not in int or out of range" );
2033
2034         con = add_new_constraint( type );
2035         if( self->pchan ) {
2036                 BLI_addtail( &self->pchan->constraints, con );
2037                 update_pose_constraint_flags( self->obj->pose );
2038         }
2039         else
2040                 BLI_addtail( &self->obj->constraints, con );
2041
2042         return Constraint_CreatePyObject( self->pchan, self->obj, con );
2043 }
2044
2045 /* move the constraint up in the stack */
2046
2047 static PyObject *ConstraintSeq_moveUp( BPy_ConstraintSeq *self, BPy_Constraint *value )
2048 {
2049         bConstraint *con = locate_constr( self,  value );
2050
2051         /* if we can't locate the constraint, return (exception already set) */
2052         if( !con )
2053                 return (PyObject *)NULL;
2054
2055         const_moveUp( self->obj, con );
2056         Py_RETURN_NONE;
2057 }
2058
2059 /* move the constraint down in the stack */
2060
2061 static PyObject *ConstraintSeq_moveDown( BPy_ConstraintSeq *self, BPy_Constraint *value )
2062 {
2063         bConstraint *con = locate_constr( self,  value );
2064
2065         /* if we can't locate the constraint, return (exception already set) */
2066         if( !con )
2067                 return (PyObject *)NULL;
2068
2069         const_moveDown( self->obj, con );
2070         Py_RETURN_NONE;
2071 }
2072
2073 /* remove an existing constraint */
2074
2075 static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, BPy_Constraint *value )
2076 {
2077         bConstraint *con = locate_constr( self,  value );
2078
2079         /* if we can't locate the constraint, return (exception already set) */
2080         if( !con )
2081                 return (PyObject *)NULL;
2082
2083         /* do the actual removal */
2084         if( self->pchan )
2085                 BLI_remlink( &self->pchan->constraints, con );
2086         else
2087                 BLI_remlink( &self->obj->constraints, con);
2088         del_constr_func( self->obj, con );
2089
2090         /* erase the link to the constraint */
2091         value->con = NULL;
2092
2093         Py_RETURN_NONE;
2094 }
2095
2096 /*****************************************************************************/
2097 /* Function:    ConstraintSeq_dealloc                                        */
2098 /* Description: This is a callback function for the BPy_ConstraintSeq type.  */
2099 /*              It destroys data when the object is deleted.                 */
2100 /*****************************************************************************/
2101 static void ConstraintSeq_dealloc( BPy_Constraint * self )
2102 {
2103         PyObject_DEL( self );
2104 }
2105
2106 /*****************************************************************************/
2107 /* Python BPy_ConstraintSeq methods table:                                   */
2108 /*****************************************************************************/
2109 static PyMethodDef BPy_ConstraintSeq_methods[] = {
2110         /* name, method, flags, doc */
2111         {"append", ( PyCFunction ) ConstraintSeq_append, METH_O,
2112          "(type) - add a new constraint, where type is the constraint type"},
2113         {"remove", ( PyCFunction ) ConstraintSeq_remove, METH_O,
2114          "(con) - remove an existing constraint, where con is a constraint from this object."},
2115         {"moveUp", ( PyCFunction ) ConstraintSeq_moveUp, METH_O,
2116          "(con) - Move constraint up in stack"},
2117         {"moveDown", ( PyCFunction ) ConstraintSeq_moveDown, METH_O,
2118          "(con) - Move constraint down in stack"},
2119         {NULL, NULL, 0, NULL}
2120 };
2121
2122 /*****************************************************************************/
2123 /* Python ConstraintSeq_Type structure definition:                           */
2124 /*****************************************************************************/
2125 PyTypeObject ConstraintSeq_Type = {
2126         PyObject_HEAD_INIT( NULL )  /* required py macro */
2127         0,                          /* ob_size */
2128         /*  For printing, in format "<module>.<name>" */
2129         "Blender.Constraints",      /* char *tp_name; */
2130         sizeof( BPy_ConstraintSeq ),     /* int tp_basicsize; */
2131         0,                          /* tp_itemsize;  For allocation */
2132
2133         /* Methods to implement standard operations */
2134
2135         ( destructor ) ConstraintSeq_dealloc,/* destructor tp_dealloc; */
2136         NULL,                       /* printfunc tp_print; */
2137         NULL,                       /* getattrfunc tp_getattr; */
2138         NULL,                       /* setattrfunc tp_setattr; */
2139         NULL,                       /* cmpfunc tp_compare; */
2140         ( reprfunc ) NULL,          /* reprfunc tp_repr; */
2141
2142         /* Method suites for standard classes */
2143
2144         NULL,                       /* PyNumberMethods *tp_as_number; */
2145         &ConstraintSeq_as_sequence,        /* PySequenceMethods *tp_as_sequence; */
2146         NULL,                       /* PyMappingMethods *tp_as_mapping; */
2147
2148         /* More standard operations (here for binary compatibility) */
2149
2150         NULL,                       /* hashfunc tp_hash; */
2151         NULL,                       /* ternaryfunc tp_call; */
2152         NULL,                       /* reprfunc tp_str; */
2153         NULL,                       /* getattrofunc tp_getattro; */
2154         NULL,                       /* setattrofunc tp_setattro; */
2155
2156         /* Functions to access object as input/output buffer */
2157         NULL,                       /* PyBufferProcs *tp_as_buffer; */
2158
2159   /*** Flags to define presence of optional/expanded features ***/
2160         Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
2161
2162         NULL,                       /*  char *tp_doc;  Documentation string */
2163   /*** Assigned meaning in release 2.0 ***/
2164         /* call function for all accessible objects */
2165         NULL,                       /* traverseproc tp_traverse; */
2166
2167         /* delete references to contained objects */
2168         NULL,                       /* inquiry tp_clear; */
2169
2170   /***  Assigned meaning in release 2.1 ***/
2171   /*** rich comparisons ***/
2172         NULL,                       /* richcmpfunc tp_richcompare; */
2173
2174   /***  weak reference enabler ***/
2175         0,                          /* long tp_weaklistoffset; */
2176
2177   /*** Added in release 2.2 ***/
2178         /*   Iterators */
2179         ( getiterfunc )ConstraintSeq_getIter, /* getiterfunc tp_iter; */
2180     ( iternextfunc )ConstraintSeq_nextIter, /* iternextfunc tp_iternext; */
2181
2182   /*** Attribute descriptor and subclassing stuff ***/
2183         BPy_ConstraintSeq_methods,         /* struct PyMethodDef *tp_methods; */
2184         NULL,                       /* struct PyMemberDef *tp_members; */
2185         NULL,                       /* struct PyGetSetDef *tp_getset; */
2186         NULL,                       /* struct _typeobject *tp_base; */
2187         NULL,                       /* PyObject *tp_dict; */
2188         NULL,                       /* descrgetfunc tp_descr_get; */
2189         NULL,                       /* descrsetfunc tp_descr_set; */
2190         0,                          /* long tp_dictoffset; */
2191         NULL,                       /* initproc tp_init; */
2192         NULL,                       /* allocfunc tp_alloc; */
2193         NULL,                       /* newfunc tp_new; */
2194         /*  Low-level free-memory routine */
2195         NULL,                       /* freefunc tp_free;  */
2196         /* For PyObject_IS_GC */
2197         NULL,                       /* inquiry tp_is_gc;  */
2198         NULL,                       /* PyObject *tp_bases; */
2199         /* method resolution order */
2200         NULL,                       /* PyObject *tp_mro;  */
2201         NULL,                       /* PyObject *tp_cache; */
2202         NULL,                       /* PyObject *tp_subclasses; */
2203         NULL,                       /* PyObject *tp_weaklist; */
2204         NULL
2205 };
2206
2207 /*****************************************************************************/
2208 /* Function:    PoseConstraintSeq_CreatePyObject                             */
2209 /* Description: This function will create a new BPy_ConstraintSeq from an    */
2210 /*              existing ListBase structure.                                 */
2211 /*****************************************************************************/
2212 PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan )
2213 {
2214         BPy_ConstraintSeq *pyseq;
2215         Object *ob;
2216
2217         for( ob = G.main->object.first; ob; ob = ob->id.next ) {
2218                 if( ob->type == OB_ARMATURE ) {
2219                         bPoseChannel *p = ob->pose->chanbase.first;
2220                         while( p ) {
2221                                 if( p == pchan ) {
2222                                         pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( 
2223                                                         BPy_ConstraintSeq, &ConstraintSeq_Type );
2224                                         if( !pyseq )
2225                                                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
2226                                                                 "couldn't create BPy_ConstraintSeq object" );
2227                                         pyseq->pchan = pchan;
2228                                         pyseq->obj = ob;
2229                                         return ( PyObject * ) pyseq;
2230                                 } else
2231                                         p = p->next;
2232                         }
2233                 }
2234         }
2235         return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2236                         "couldn't find ANY armature with the pose!" );
2237
2238 }
2239
2240 /*****************************************************************************/
2241 /* Function:    ObConstraintSeq_CreatePyObject                               */
2242 /* Description: This function will create a new BPy_ConstraintSeq from an    */
2243 /*              existing ListBase structure.                                 */
2244 /*****************************************************************************/
2245 PyObject *ObConstraintSeq_CreatePyObject( Object *obj )
2246 {
2247         BPy_ConstraintSeq *pyseq;
2248         pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( BPy_ConstraintSeq,
2249                         &ConstraintSeq_Type );
2250         if( !pyseq )
2251                 return EXPP_ReturnPyObjError( PyExc_MemoryError,
2252                                               "couldn't create BPy_ConstraintSeq object" );
2253         pyseq->obj = obj;
2254         pyseq->pchan = NULL;
2255         return ( PyObject * ) pyseq;
2256 }
2257
2258 static PyObject *M_Constraint_TypeDict( void )
2259 {
2260         PyObject *S = PyConstant_New(  );
2261
2262         if( S ) {
2263                 BPy_constant *d = ( BPy_constant * ) S;
2264                 PyConstant_Insert( d, "NULL", 
2265                                 PyInt_FromLong( CONSTRAINT_TYPE_NULL ) );
2266                 PyConstant_Insert( d, "TRACKTO",
2267                                 PyInt_FromLong( CONSTRAINT_TYPE_TRACKTO ) );
2268                 PyConstant_Insert( d, "IKSOLVER", 
2269                                 PyInt_FromLong( CONSTRAINT_TYPE_KINEMATIC ) );
2270                 PyConstant_Insert( d, "FOLLOWPATH", 
2271                                 PyInt_FromLong( CONSTRAINT_TYPE_FOLLOWPATH ) );
2272                 PyConstant_Insert( d, "COPYROT", 
2273                                 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIKE ) );
2274                 PyConstant_Insert( d, "COPYLOC", 
2275                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIKE ) );
2276                 PyConstant_Insert( d, "COPYSIZE", 
2277                                 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIKE ) );
2278                 PyConstant_Insert( d, "ACTION", 
2279                                 PyInt_FromLong( CONSTRAINT_TYPE_ACTION ) );
2280                 PyConstant_Insert( d, "LOCKTRACK", 
2281                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCKTRACK ) );
2282                 PyConstant_Insert( d, "STRETCHTO", 
2283                                 PyInt_FromLong( CONSTRAINT_TYPE_STRETCHTO ) );
2284                 PyConstant_Insert( d, "FLOOR", 
2285                                 PyInt_FromLong( CONSTRAINT_TYPE_MINMAX ) );
2286                 PyConstant_Insert( d, "LIMITLOC", 
2287                                 PyInt_FromLong( CONSTRAINT_TYPE_LOCLIMIT ) );
2288                 PyConstant_Insert( d, "LIMITROT", 
2289                                 PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
2290                 PyConstant_Insert( d, "LIMITSIZE", 
2291                                 PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
2292                 PyConstant_Insert( d, "RIGIDBODYJOINT", 
2293                                 PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
2294                 PyConstant_Insert( d, "CLAMPTO", 
2295                                 PyInt_FromLong( CONSTRAINT_TYPE_CLAMPTO ) );
2296                 PyConstant_Insert( d, "PYTHON",
2297                                 PyInt_FromLong( CONSTRAINT_TYPE_PYTHON ) );
2298                 PyConstant_Insert( d, "CHILDOF",
2299                                 PyInt_FromLong( CONSTRAINT_TYPE_CHILDOF ) );
2300                 PyConstant_Insert( d, "TRANSFORM",
2301                                 PyInt_FromLong( CONSTRAINT_TYPE_TRANSFORM ) );
2302         }
2303         return S;
2304 }
2305
2306 static PyObject *M_Constraint_SettingsDict( void )
2307 {
2308         PyObject *S = PyConstant_New(  );
2309         
2310         if( S ) {
2311                 BPy_constant *d = ( BPy_constant * ) S;
2312                 PyConstant_Insert( d, "XROT",
2313                                 PyInt_FromLong( EXPP_CONSTR_XROT ) );
2314                 PyConstant_Insert( d, "YROT",
2315                                 PyInt_FromLong( EXPP_CONSTR_YROT ) );
2316                 PyConstant_Insert( d, "ZROT",
2317                                 PyInt_FromLong( EXPP_CONSTR_ZROT ) );
2318                 PyConstant_Insert( d, "XSIZE",
2319                                 PyInt_FromLong( EXPP_CONSTR_XSIZE ) );
2320                 PyConstant_Insert( d, "YSIZE",
2321                                 PyInt_FromLong( EXPP_CONSTR_YSIZE ) );
2322                 PyConstant_Insert( d, "ZSIZE",
2323                                 PyInt_FromLong( EXPP_CONSTR_ZSIZE ) );
2324                 PyConstant_Insert( d, "XLOC",
2325                                 PyInt_FromLong( EXPP_CONSTR_XLOC ) );
2326                 PyConstant_Insert( d, "YLOC",
2327                                 PyInt_FromLong( EXPP_CONSTR_YLOC ) );
2328                 PyConstant_Insert( d, "ZLOC",
2329                                 PyInt_FromLong( EXPP_CONSTR_ZLOC ) );
2330
2331                 PyConstant_Insert( d, "UPX",
2332                                 PyInt_FromLong( UP_X ) );
2333                 PyConstant_Insert( d, "UPY",
2334                                 PyInt_FromLong( UP_Y ) );
2335                 PyConstant_Insert( d, "UPZ",
2336                                 PyInt_FromLong( UP_Z ) );
2337
2338                 PyConstant_Insert( d, "TRACKX",
2339                                 PyInt_FromLong( TRACK_X ) );
2340                 PyConstant_Insert( d, "TRACKY",
2341                                 PyInt_FromLong( TRACK_Y ) );
2342                 PyConstant_Insert( d, "TRACKZ",
2343                                 PyInt_FromLong( TRACK_Z ) );
2344                 PyConstant_Insert( d, "TRACKNEGX",
2345                                 PyInt_FromLong( TRACK_nX ) );
2346                 PyConstant_Insert( d, "TRACKNEGY",
2347                                 PyInt_FromLong( TRACK_nY ) );
2348                 PyConstant_Insert( d, "TRACKNEGZ",
2349                                 PyInt_FromLong( TRACK_nZ ) );
2350
2351                 PyConstant_Insert( d, "VOLUMEXZ",
2352                                 PyInt_FromLong( VOLUME_XZ ) );
2353                 PyConstant_Insert( d, "VOLUMEX",
2354                                 PyInt_FromLong( VOLUME_X ) );
2355                 PyConstant_Insert( d, "VOLUMEZ",
2356                                 PyInt_FromLong( VOLUME_Z ) );
2357                 PyConstant_Insert( d, "VOLUMENONE",
2358                                 PyInt_FromLong( NO_VOLUME ) );
2359
2360                 PyConstant_Insert( d, "PLANEX",
2361                                 PyInt_FromLong( PLANE_X ) );
2362                 PyConstant_Insert( d, "PLANEY",
2363                                 PyInt_FromLong( PLANE_Y ) );
2364                 PyConstant_Insert( d, "PLANEZ",
2365                                 PyInt_FromLong( PLANE_Z ) );
2366
2367                 PyConstant_Insert( d, "LOCKX",
2368                                 PyInt_FromLong( LOCK_X ) );
2369                 PyConstant_Insert( d, "LOCKY",
2370                                 PyInt_FromLong( LOCK_Y ) );
2371                 PyConstant_Insert( d, "LOCKZ",
2372                                 PyInt_FromLong( LOCK_Z ) );
2373
2374                 PyConstant_Insert( d, "MAXX",
2375                                 PyInt_FromLong( EXPP_CONSTR_MAXX ) );
2376                 PyConstant_Insert( d, "MAXY",
2377                                 PyInt_FromLong( EXPP_CONSTR_MAXY ) );
2378                 PyConstant_Insert( d, "MAXZ",
2379                                 PyInt_FromLong( EXPP_CONSTR_MAXZ ) );
2380                 PyConstant_Insert( d, "MINX",
2381                                 PyInt_FromLong( EXPP_CONSTR_MINX ) );
2382                 PyConstant_Insert( d, "MINY",
2383                                 PyInt_FromLong( EXPP_CONSTR_MINY ) );
2384                 PyConstant_Insert( d, "MINZ",
2385                                 PyInt_FromLong( EXPP_CONSTR_MINZ ) );
2386
2387                 PyConstant_Insert( d, "COPYX",
2388                                 PyInt_FromLong( LOCLIKE_X ) );
2389                 PyConstant_Insert( d, "COPYY",
2390                                 PyInt_FromLong( LOCLIKE_Y ) );
2391                 PyConstant_Insert( d, "COPYZ",
2392                                 PyInt_FromLong( LOCLIKE_Z ) );
2393                 PyConstant_Insert( d, "COPYXINVERT",
2394                                 PyInt_FromLong( LOCLIKE_X_INVERT ) );
2395                 PyConstant_Insert( d, "COPYYINVERT",
2396                                 PyInt_FromLong( LOCLIKE_Y_INVERT ) );
2397                 PyConstant_Insert( d, "COPYZINVERT",
2398                                 PyInt_FromLong( LOCLIKE_Z_INVERT ) );
2399                                 
2400                 PyConstant_Insert( d, "PARLOCX",
2401                                 PyInt_FromLong( CHILDOF_LOCX ) );
2402                 PyConstant_Insert( d, "PARLOCY",
2403                                 PyInt_FromLong( CHILDOF_LOCY ) );
2404                 PyConstant_Insert( d, "PARLOCZ",
2405                                 PyInt_FromLong( CHILDOF_LOCZ ) );
2406                 PyConstant_Insert( d, "PARROTX",
2407                                 PyInt_FromLong( CHILDOF_ROTX ) );
2408                 PyConstant_Insert( d, "PARROTY",
2409                                 PyInt_FromLong( CHILDOF_ROTY ) );
2410                 PyConstant_Insert( d, "PARROTZ",
2411                                 PyInt_FromLong( CHILDOF_ROTZ ) );
2412                 PyConstant_Insert( d, "PARSIZEX",
2413                                 PyInt_FromLong( CHILDOF_LOCX ) );
2414                 PyConstant_Insert( d, "PARSIZEY",
2415                                 PyInt_FromLong( CHILDOF_SIZEY ) );
2416                 PyConstant_Insert( d, "PARSIZEZ",
2417                                 PyInt_FromLong( CHILDOF_SIZEZ ) );
2418                                 
2419                 PyConstant_Insert( d, "CLAMPAUTO",
2420                                 PyInt_FromLong( CLAMPTO_AUTO ) );
2421                 PyConstant_Insert( d, "CLAMPX",
2422                                 PyInt_FromLong( CLAMPTO_X ) );
2423                 PyConstant_Insert( d, "CLAMPY",
2424                                 PyInt_FromLong( CLAMPTO_Y ) );
2425                 PyConstant_Insert( d, "CLAMPZ",
2426                                 PyInt_FromLong( CLAMPTO_Z ) );
2427                 PyConstant_Insert( d, "CLAMPCYCLIC",
2428                                 PyInt_FromLong( EXPP_CONSTR_CLAMPCYCLIC ));
2429
2430                 PyConstant_Insert( d, "TARGET",
2431                                 PyInt_FromLong( EXPP_CONSTR_TARGET ) );
2432                 PyConstant_Insert( d, "STRETCH", 
2433                                 PyInt_FromLong( EXPP_CONSTR_STRETCH ) );
2434                 PyConstant_Insert( d, "ITERATIONS", 
2435                                 PyInt_FromLong( EXPP_CONSTR_ITERATIONS ) );
2436                 PyConstant_Insert( d, "BONE", 
2437                                 PyInt_FromLong( EXPP_CONSTR_BONE ) );
2438                 PyConstant_Insert( d, "CHAINLEN", 
2439                                 PyInt_FromLong( EXPP_CONSTR_CHAINLEN ) );
2440                 PyConstant_Insert( d, "POSWEIGHT", 
2441                                 PyInt_FromLong( EXPP_CONSTR_POSWEIGHT ) );
2442                 PyConstant_Insert( d, "ROTWEIGHT", 
2443                                 PyInt_FromLong( EXPP_CONSTR_ROTWEIGHT ) );
2444                 PyConstant_Insert( d, "ROTATE", 
2445                                 PyInt_FromLong( EXPP_CONSTR_ROTATE ) );
2446                 PyConstant_Insert( d, "USETIP", 
2447                                 PyInt_FromLong( EXPP_CONSTR_USETIP ) );
2448
2449                 PyConstant_Insert( d, "ACTION", 
2450                                 PyInt_FromLong( EXPP_CONSTR_ACTION ) );
2451                 PyConstant_Insert( d, "START", 
2452                                 PyInt_FromLong( EXPP_CONSTR_START ) );
2453                 PyConstant_Insert( d, "END", 
2454                                 PyInt_FromLong( EXPP_CONSTR_END ) );
2455                 PyConstant_Insert( d, "MIN", 
2456                                 PyInt_FromLong( EXPP_CONSTR_MIN ) );
2457                 PyConstant_Insert( d, "MAX", 
2458                                 PyInt_FromLong( EXPP_CONSTR_MAX ) );
2459                 PyConstant_Insert( d, "KEYON", 
2460                                 PyInt_FromLong( EXPP_CONSTR_KEYON ) );
2461
2462                 PyConstant_Insert( d, "TRACK", 
2463                                 PyInt_FromLong( EXPP_CONSTR_TRACK ) );
2464                 PyConstant_Insert( d, "UP", 
2465                                 PyInt_FromLong( EXPP_CONSTR_UP ) );
2466
2467                 PyConstant_Insert( d, "RESTLENGTH",
2468                                 PyInt_FromLong( EXPP_CONSTR_RESTLENGTH ) );
2469                 PyConstant_Insert( d, "VOLVARIATION",
2470                                 PyInt_FromLong( EXPP_CONSTR_VOLVARIATION ) );
2471                 PyConstant_Insert( d, "VOLUMEMODE",
2472                                 PyInt_FromLong( EXPP_CONSTR_VOLUMEMODE ) );
2473                 PyConstant_Insert( d, "PLANE",
2474                                 PyInt_FromLong( EXPP_CONSTR_PLANE ) );
2475
2476                 PyConstant_Insert( d, "FOLLOW",
2477                                 PyInt_FromLong( EXPP_CONSTR_FOLLOW ) );
2478                 PyConstant_Insert( d, "OFFSET",
2479                                 PyInt_FromLong( EXPP_CONSTR_OFFSET ) );
2480                 PyConstant_Insert( d, "FORWARD",
2481                                 PyInt_FromLong( EXPP_CONSTR_FORWARD ) );
2482
2483                 PyConstant_Insert( d, "LOCK",
2484                                 PyInt_FromLong( EXPP_CONSTR_LOCK ) );
2485
2486                 PyConstant_Insert( d, "COPY",
2487                                 PyInt_FromLong( EXPP_CONSTR_COPY ) );
2488                 PyConstant_Insert( d, "LIMIT",
2489                                 PyInt_FromLong( EXPP_CONSTR_LIMIT ) );
2490                 PyConstant_Insert( d, "CLAMP",
2491                                 PyInt_FromLong( EXPP_CONSTR_CLAMP ) );
2492                 
2493                 PyConstant_Insert( d, "LIMIT_XMIN",
2494                                 PyInt_FromLong( EXPP_CONSTR_LIMXMIN ) );
2495                 PyConstant_Insert( d, "LIMIT_XMAX",
2496                                 PyInt_FromLong( EXPP_CONSTR_LIMXMAX ) );
2497                 PyConstant_Insert( d, "LIMIT_YMIN",
2498                                 PyInt_FromLong( EXPP_CONSTR_LIMYMIN ) );
2499                 PyConstant_Insert( d, "LIMIT_YMAX",
2500                                 PyInt_FromLong( EXPP_CONSTR_LIMYMAX ) );
2501                 PyConstant_Insert( d, "LIMIT_ZMIN",
2502                                 PyInt_FromLong( EXPP_CONSTR_LIMZMIN ) );
2503                 PyConstant_Insert( d, "LIMIT_ZMAX",
2504                                 PyInt_FromLong( EXPP_CONSTR_LIMZMAX ) );
2505                 
2506                 PyConstant_Insert( d, "LIMIT_XROT",
2507                                 PyInt_FromLong( EXPP_CONSTR_LIMXROT ) );
2508                 PyConstant_Insert( d, "LIMIT_YROT",
2509                                 PyInt_FromLong( EXPP_CONSTR_LIMYROT ) );
2510                 PyConstant_Insert( d, "LIMIT_ZROT",
2511                                 PyInt_FromLong( EXPP_CONSTR_LIMZROT ) );
2512                 
2513                 PyConstant_Insert( d, "XMIN",
2514                                 PyInt_FromLong( EXPP_CONSTR_XMIN ) );
2515                 PyConstant_Insert( d, "XMAX",
2516                                 PyInt_FromLong( EXPP_CONSTR_XMAX ) );
2517                 PyConstant_Insert( d, "YMIN",
2518                                 PyInt_FromLong( EXPP_CONSTR_YMIN ) );
2519                 PyConstant_Insert( d, "YMAX",
2520                                 PyInt_FromLong( EXPP_CONSTR_YMAX ) );
2521                 PyConstant_Insert( d, "ZMIN",
2522                                 PyInt_FromLong( EXPP_CONSTR_ZMIN ) );
2523                 PyConstant_Insert( d, "ZMAX",
2524                                 PyInt_FromLong( EXPP_CONSTR_ZMAX ) );
2525                                 
2526                 PyConstant_Insert( d, "SCRIPT",
2527                                 PyInt_FromLong( EXPP_CONSTR_SCRIPT ) );
2528                 PyConstant_Insert( d, "PROPERTIES",
2529                                 PyInt_FromLong( EXPP_CONSTR_PROPS ) );
2530                                 
2531                 PyConstant_Insert( d, "FROM",
2532                                 PyInt_FromLong( EXPP_CONSTR_FROM ) );
2533                 PyConstant_Insert( d, "TO",
2534                                 PyInt_FromLong( EXPP_CONSTR_TO ) );
2535                 PyConstant_Insert( d, "EXTRAPOLATE",
2536                                 PyInt_FromLong( EXPP_CONSTR_EXPO ) );
2537                 PyConstant_Insert( d, "MAPX",
2538                                 PyInt_FromLong( EXPP_CONSTR_MAPX ) );
2539                 PyConstant_Insert( d, "MAPY",
2540                                 PyInt_FromLong( EXPP_CONSTR_MAPY ) );
2541                 PyConstant_Insert( d, "MAPZ",
2542                                 PyInt_FromLong( EXPP_CONSTR_MAPZ ) );
2543                 PyConstant_Insert( d, "FROM_MINX",
2544                                 PyInt_FromLong( EXPP_CONSTR_FROMMINX ) );
2545                 PyConstant_Insert( d, "FROM_MAXX",
2546                                 PyInt_FromLong( EXPP_CONSTR_FROMMAXX ) );
2547                 PyConstant_Insert( d, "FROM_MINY",
2548                                 PyInt_FromLong( EXPP_CONSTR_FROMMINY ) );
2549                 PyConstant_Insert( d, "FROM_MAXY",
2550                                 PyInt_FromLong( EXPP_CONSTR_FROMMAXY ) );
2551                 PyConstant_Insert( d, "FROM_MINZ",
2552                                 PyInt_FromLong( EXPP_CONSTR_FROMMINZ ) );
2553                 PyConstant_Insert( d, "FROM_MAXZ",
2554                                 PyInt_FromLong( EXPP_CONSTR_FROMMAXZ ) );
2555                 PyConstant_Insert( d, "TO_MINX",
2556                                 PyInt_FromLong( EXPP_CONSTR_TOMINX ) );
2557                 PyConstant_Insert( d, "TO_MAXX",
2558                                 PyInt_FromLong( EXPP_CONSTR_TOMAXX ) );
2559                 PyConstant_Insert( d, "TO_MINY",
2560                                 PyInt_FromLong( EXPP_CONSTR_TOMINY ) );
2561                 PyConstant_Insert( d, "TO_MAXY",
2562                                 PyInt_FromLong( EXPP_CONSTR_TOMAXY ) );
2563                 PyConstant_Insert( d, "TO_MINZ",
2564                                 PyInt_FromLong( EXPP_CONSTR_TOMINZ ) );
2565                 PyConstant_Insert( d, "TO_MAXZ",
2566                                 PyInt_FromLong( EXPP_CONSTR_TOMAXZ ) );
2567                                 
2568                 PyConstant_Insert( d, "LOC",
2569                                 PyInt_FromLong( 0 ) );
2570                 PyConstant_Insert( d, "ROT",
2571                                 PyInt_FromLong( 1 ) );
2572                 PyConstant_Insert( d, "SCALE",
2573                                 PyInt_FromLong( 2 ) );
2574                                 
2575                 PyConstant_Insert( d, "CONSTR_RB_TYPE",
2576                                 PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
2577                 PyConstant_Insert( d, "CONSTR_RB_BALL",
2578                                 PyInt_FromLong( EXPP_CONSTR_RB_BALL ) );
2579                 PyConstant_Insert( d, "CONSTR_RB_HINGE",
2580                                 PyInt_FromLong( EXPP_CONSTR_RB_HINGE ) );
2581                 PyConstant_Insert( d, "CONSTR_RB_GENERIC6DOF",
2582                                 PyInt_FromLong( EXPP_CONSTR_RB_GENERIC6DOF ) );
2583                 PyConstant_Insert( d, "CONSTR_RB_VEHICLE",
2584                                 PyInt_FromLong( EXPP_CONSTR_RB_VEHICLE ) );
2585                 PyConstant_Insert( d, "CONSTR_RB_PIVX",
2586                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVX ) );
2587                 PyConstant_Insert( d, "CONSTR_RB_PIVY",
2588                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVY ) );
2589                 PyConstant_Insert( d, "CONSTR_RB_PIVZ",
2590                                 PyInt_FromLong( EXPP_CONSTR_RB_PIVZ ) );
2591                 PyConstant_Insert( d, "CONSTR_RB_AXX",
2592                                 PyInt_FromLong( EXPP_CONSTR_RB_AXX ) );
2593                 PyConstant_Insert( d, "CONSTR_RB_AXY",
2594                                 PyInt_FromLong( EXPP_CONSTR_RB_AXY ) );
2595                 PyConstant_Insert( d, "CONSTR_RB_AXZ",
2596                                 PyInt_FromLong( EXPP_CONSTR_RB_AXZ ) );
2597                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT0",
2598                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT0 ) );
2599                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT1",
2600                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT1 ) );
2601                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT2",
2602                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT2 ) );
2603                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT3",
2604                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT3 ) );
2605                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT4",
2606                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT4 ) );
2607                 PyConstant_Insert( d, "CONSTR_RB_MINLIMIT5",
2608                                 PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT5 ) );
2609                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT0",
2610                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT0 ) );
2611                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT1",
2612                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT1 ) );
2613                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT2",
2614                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT2 ) );
2615                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT3",
2616                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT3 ) );
2617                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT4",
2618                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT4 ) );
2619                 PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT5",
2620                                 PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT5 ) );                           
2621                 PyConstant_Insert( d, "CONSTR_RB_EXTRAFZ",
2622                                 PyInt_FromLong( EXPP_CONSTR_RB_EXTRAFZ ) );
2623                 PyConstant_Insert( d, "CONSTR_RB_FLAG",
2624                                 PyInt_FromLong( EXPP_CONSTR_RB_FLAG ) );
2625                                 
2626                                 
2627                 PyConstant_Insert( d, "OWNERSPACE",
2628                                 PyInt_FromLong( EXPP_CONSTR_OWNSPACE ) );
2629                 PyConstant_Insert( d, "TARGETSPACE",
2630                                 PyInt_FromLong( EXPP_CONSTR_TARSPACE ) );
2631                                 
2632                 PyConstant_Insert( d, "SPACE_WORLD",
2633                                 PyInt_FromLong( CONSTRAINT_SPACE_WORLD) );
2634                 PyConstant_Insert( d, "SPACE_LOCAL",
2635                                 PyInt_FromLong( CONSTRAINT_SPACE_LOCAL ) );
2636                 PyConstant_Insert( d, "SPACE_POSE",
2637                                 PyInt_FromLong( CONSTRAINT_SPACE_POSE) );
2638                 PyConstant_Insert( d, "SPACE_PARLOCAL",
2639                                 PyInt_FromLong( CONSTRAINT_SPACE_PARLOCAL ) );
2640         }
2641         return S;
2642 }
2643
2644 /*****************************************************************************/
2645 /* Function:              Constraint_Init                                    */
2646 /*****************************************************************************/
2647 PyObject *Constraint_Init( void )
2648 {
2649         PyObject *submodule;
2650         PyObject *TypeDict = M_Constraint_TypeDict( );
2651         PyObject *SettingsDict = M_Constraint_SettingsDict( );
2652
2653         if( PyType_Ready( &ConstraintSeq_Type ) < 0
2654                         || PyType_Ready( &Constraint_Type ) < 0 )
2655                 return NULL;
2656
2657         submodule = Py_InitModule3( "Blender.Constraint", NULL,
2658                         "Constraint module for accessing and creating constraint data" );
2659
2660         if( TypeDict )
2661                 PyModule_AddObject( submodule, "Type", TypeDict );
2662         
2663         if( SettingsDict )
2664                 PyModule_AddObject( submodule, "Settings", SettingsDict );
2665         
2666         return submodule;
2667 }