diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-08-18 16:40:31 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-08-18 16:40:31 +0400 |
commit | 410dbe903737fc2a3b70c001388fded13082fa3d (patch) | |
tree | 37299fa88f61d4b5a4b1d4f4cabecabe4b842f9f /source | |
parent | 5aecd230cbbc421e3181ee4f1d87c5babb36343a (diff) |
python get/set material function for 3d text
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/api2_2x/Text3d.c | 46 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Text3d.py | 20 |
2 files changed, 66 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Text3d.c b/source/blender/python/api2_2x/Text3d.c index 5137e989b8d..202195cdcb4 100644 --- a/source/blender/python/api2_2x/Text3d.c +++ b/source/blender/python/api2_2x/Text3d.c @@ -132,9 +132,12 @@ static PyObject *Text3d_getAlignment( BPy_Text3d * self ); static PyObject *Text3d_setAlignment( BPy_Text3d * self, PyObject * args ); static PyObject *Text3d_getFont( BPy_Text3d * self ); static PyObject *Text3d_setFont( BPy_Text3d * self, PyObject * args ); +static PyObject *Text3d_getMaterial( BPy_Text3d * self, PyObject * value ); +static PyObject *Text3d_setMaterial( BPy_Text3d * self, PyObject * args ); static PyObject *Text3d_addFrame( BPy_Text3d * self ); static PyObject *Text3d_removeFrame( BPy_Text3d * self, PyObject * args ); + /*****************************************************************************/ /* Python BPy_Text3d methods table: */ /*****************************************************************************/ @@ -210,6 +213,10 @@ static PyMethodDef BPy_Text3d_methods[] = { METH_NOARGS, "() - Gets font list for Text3d"}, {"setFont", ( PyCFunction ) Text3d_setFont, METH_VARARGS, "() - Sets font for Text3d"}, + {"getMaterial", ( PyCFunction ) Text3d_getMaterial, + METH_O, "() - Gets font list for Text3d"}, + {"setMaterial", ( PyCFunction ) Text3d_setMaterial, + METH_VARARGS, "() - Sets font for Text3d"}, {"addFrame", ( PyCFunction ) Text3d_addFrame, METH_NOARGS, "() - adds a new text frame"}, {"removeFrame", ( PyCFunction ) Text3d_removeFrame, @@ -1132,6 +1139,45 @@ static PyObject *Text3d_setFont( BPy_Text3d * self, PyObject * args ) Py_RETURN_NONE; } +/* todo, add style access, will be almost exact copy of these 2 */ +static PyObject *Text3d_getMaterial( BPy_Text3d * self, PyObject * value ) +{ + int index = PyInt_AsLong( value ); + if (index == -1 && PyErr_Occurred()) + return EXPP_ReturnPyObjError( PyExc_TypeError, "expected a character index" ); + + if (index < 0) + index = self->curve->len + index; + + if ( index < 0 || index >= self->curve->len ) + return EXPP_ReturnPyObjError( PyExc_IndexError, "character index out of range" ); + + return PyInt_FromLong( self->curve->strinfo[index].mat_nr ); +} + +static PyObject *Text3d_setMaterial( BPy_Text3d * self, PyObject * args ) +{ + int index, mat_nr; + if( !PyArg_ParseTuple( args, "ii",&index, &mat_nr) ) + return NULL; /* Python error is ok */ + + if (index < 0) + index = self->curve->len + index; + + if ( index < 0 || index >= self->curve->len ) + return EXPP_ReturnPyObjError( PyExc_IndexError, "character index out of range" ); + + if (mat_nr < 0) + mat_nr = self->curve->totcol + mat_nr; + + if ( mat_nr < 0 || mat_nr >= self->curve->totcol ) + return EXPP_ReturnPyObjError( PyExc_IndexError, "material index out of range" ); + + self->curve->strinfo[index].mat_nr = mat_nr; + + Py_RETURN_NONE; +} + static PyObject *Text3d_addFrame( BPy_Text3d * self ) { Curve *cu = self->curve; diff --git a/source/blender/python/api2_2x/doc/Text3d.py b/source/blender/python/api2_2x/doc/Text3d.py index a7d8c585078..4bd989014f4 100644 --- a/source/blender/python/api2_2x/doc/Text3d.py +++ b/source/blender/python/api2_2x/doc/Text3d.py @@ -287,6 +287,26 @@ class Text3d: @param align: The new text3d's Alignment value. """ + def getMaterial(index): + """ + get the material index of a character. + @rtype: int + @return: the material index if the character + @type index: int + @param index: the index of the character in a string + """ + + def setMaterial(index, material_index): + """ + Set a characters material. + @note: after changing this youll need to update the object with object.makeDisplayList() to see the changes. + @rtype: None + @type index: int + @param index: the index of the character in a string + @type material_index: int + @param material_index: the material index set set the character. + """ + def addFrame(): """ Adds a text frame. maximum number of frames is 255. |