Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Alatalo <antont@kyperjokki.fi>2005-12-07 22:36:01 +0300
committerToni Alatalo <antont@kyperjokki.fi>2005-12-07 22:36:01 +0300
commit5b71510ecf7ecc773661fa76641e47134afde6b9 (patch)
tree25d728c4f10c505853470f4949c85c9976ab7f19 /source/blender/python/api2_2x/Armature.c
parentddc98d130767f0be2a2983b78aa31547da6e3b46 (diff)
A patch from Ken Hughes per request of Bassam here at Orange: Python access to armature visibility layers.
Diffstat (limited to 'source/blender/python/api2_2x/Armature.c')
-rw-r--r--source/blender/python/api2_2x/Armature.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Armature.c b/source/blender/python/api2_2x/Armature.c
index e6482c87a54..f728f3f19d1 100644
--- a/source/blender/python/api2_2x/Armature.c
+++ b/source/blender/python/api2_2x/Armature.c
@@ -546,6 +546,71 @@ AttributeError:
return EXPP_intError(PyExc_AttributeError, "%s%s",
sArmatureBadArgs, "Expects True or False");
}
+//------------------------Armature.layers (getter)
+static PyObject *Armature_getLayers(BPy_Armature *self, void *closure)
+{
+ int layers, bit = 0, val = 0;
+ PyObject *item = NULL, *laylist = PyList_New( 0 );
+
+ if( !laylist )
+ return EXPP_ReturnPyObjError( PyExc_MemoryError,
+ "couldn't create pylist!" );
+
+ layers = self->armature->layer;
+
+ while( bit < 20 ) {
+ val = 1 << bit;
+ if( layers & val ) {
+ item = Py_BuildValue( "i", bit + 1 );
+ PyList_Append( laylist, item );
+ Py_DECREF( item );
+ }
+ bit++;
+ }
+ return laylist;
+}
+//------------------------Armature.layer (setter)
+static int Armature_setLayers(BPy_Armature *self, PyObject *value, void *closure)
+{
+ if(value){
+ if(PyList_Check(value)){
+ int layers = 0, len_list = 0;
+ int val;
+ PyObject *item = NULL;
+
+ len_list = PyList_Size(value);
+
+ if( len_list == 0 )
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "list can't be empty, at least one layer must be set" );
+
+ while( len_list ) {
+ --len_list;
+ item = PyList_GetItem( value, len_list );
+ if( !PyInt_Check( item ) )
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "list must contain only integer numbers" );
+
+ val = ( int ) PyInt_AsLong( item );
+ if( val < 1 || val > 20 )
+ return EXPP_ReturnIntError( PyExc_AttributeError,
+ "layer values must be in the range [1, 20]" );
+
+ layers |= 1 << ( val - 1 );
+ }
+
+ /* update any bases pointing to our object */
+ self->armature->layer = layers;
+
+ return 0;
+ }
+ }
+ goto AttributeError;
+
+AttributeError:
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected a list of integers" );
+}
//------------------------Armature.mirrorEdit (getter)
static PyObject *Armature_getMirrorEdit(BPy_Armature *self, void *closure)
{
@@ -938,6 +1003,8 @@ static PyGetSetDef BPy_Armature_getset[] = {
"Enable/Disable X-axis mirrored editing", NULL},
{"autoIK", (getter)Armature_getAutoIK, (setter)Armature_setAutoIK,
"Adds temporal IK chains while grabbing bones", NULL},
+ {"layers", (getter)Armature_getLayers, (setter)Armature_setLayers,
+ "List of layers for the armature", NULL},
{NULL}
};
//------------------------tp_new