From 60a2977dcf61b8e93f1c70f4a9fc1e8e7b43b6d2 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 22 Dec 2006 04:46:37 +0000 Subject: [PATCH] adding ob.activeMaterial - allows you to get/set the active material for an object. --- source/blender/python/api2_2x/Object.c | 14 ++++++++++++++ source/blender/python/api2_2x/doc/Object.py | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 448246c536d..0d4b2bcc6fd 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -173,6 +173,7 @@ enum obj_consts { EXPP_OBJ_ATTR_DRAWSIZE, EXPP_OBJ_ATTR_PARENT_TYPE, EXPP_OBJ_ATTR_PASSINDEX, + EXPP_OBJ_ATTR_ACT_MATERIAL, EXPP_OBJ_ATTR_PI_SURFACEDAMP, /* these need to stay together */ EXPP_OBJ_ATTR_PI_RANDOMDAMP, /* and in order */ @@ -3673,6 +3674,9 @@ static PyObject *getIntAttr( BPy_Object *self, void *type ) case EXPP_OBJ_ATTR_PASSINDEX: param = object->index; break; + case EXPP_OBJ_ATTR_ACT_MATERIAL: + param = object->actcol; + break; default: return EXPP_ReturnPyObjError( PyExc_RuntimeError, "undefined type in getIntAttr" ); @@ -3728,6 +3732,12 @@ static int setIntAttrClamp( BPy_Object *self, PyObject *value, void *type ) size = 'H'; /* in case max is later made > 32767 */ param = (void *)&object->index; break; + case EXPP_OBJ_ATTR_ACT_MATERIAL: + min = 1; + max = object->totcol; + size = 'b'; /* in case max is later made > 128 */ + param = (void *)&object->actcol; + break; default: return EXPP_ReturnIntError( PyExc_RuntimeError, "undefined type in setIntAttrClamp"); @@ -4930,6 +4940,10 @@ static PyGetSetDef BPy_Object_getseters[] = { (getter)getIntAttr, (setter)setIntAttrClamp, "Index for object masks in the compositor", (void *)EXPP_OBJ_ATTR_PASSINDEX}, + {"activeMaterial", + (getter)getIntAttr, (setter)setIntAttrClamp, + "Index for the active material (displayed in the material panel)", + (void *)EXPP_OBJ_ATTR_ACT_MATERIAL}, {"mat", (getter)Object_getMatrixWorld, (setter)NULL, "worldspace matrix: absolute, takes vertex parents, tracking and Ipos into account", diff --git a/source/blender/python/api2_2x/doc/Object.py b/source/blender/python/api2_2x/doc/Object.py index 2d2374444d7..07599e84c4d 100644 --- a/source/blender/python/api2_2x/doc/Object.py +++ b/source/blender/python/api2_2x/doc/Object.py @@ -449,6 +449,13 @@ class Object: @ivar passIndex: Index # for the IndexOB render pass. Value is clamped to [0,1000]. @type passIndex: int + @ivar activeMaterial: The active material index for this object. + + The active index is used to select the material to edit in the material buttons, + new data created will also use the active material. + + Value is clamped to [1,len(ob.materials)]. - [0,0] when there is no materials applied to the object. + @type activeMaterial: int @ivar drawSize: The size to display the Empty. Value clamped to [0.01,10.0]. @type drawSize: float