Revision: 16171
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16171
Author:   campbellbarton
Date:     2008-08-18 14:40:31 +0200 (Mon, 18 Aug 2008)

Log Message:
-----------
python get/set material function for 3d text

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Text3d.c
    trunk/blender/source/blender/python/api2_2x/doc/Text3d.py

Modified: trunk/blender/source/blender/python/api2_2x/Text3d.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Text3d.c        2008-08-18 
12:09:33 UTC (rev 16170)
+++ trunk/blender/source/blender/python/api2_2x/Text3d.c        2008-08-18 
12:40:31 UTC (rev 16171)
@@ -132,9 +132,12 @@
 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 @@
        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 @@
        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;

Modified: trunk/blender/source/blender/python/api2_2x/doc/Text3d.py
===================================================================
--- trunk/blender/source/blender/python/api2_2x/doc/Text3d.py   2008-08-18 
12:09:33 UTC (rev 16170)
+++ trunk/blender/source/blender/python/api2_2x/doc/Text3d.py   2008-08-18 
12:40:31 UTC (rev 16171)
@@ -287,6 +287,26 @@
                @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.


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to