python get/set material function for 3d text

This commit is contained in:
Campbell Barton
2008-08-18 12:40:31 +00:00
parent 5aecd230cb
commit 410dbe9037
2 changed files with 66 additions and 0 deletions

View File

@@ -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;

View File

@@ -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.