Python API

----------
Access to empty shapes by object.emptyShape attribute, contributed by Domino
Marama (thanks!)
This commit is contained in:
Ken Hughes 2008-08-21 16:10:30 +00:00
parent e912ca9331
commit 7e0c880c2e
2 changed files with 43 additions and 2 deletions

@ -204,6 +204,7 @@ enum obj_consts {
EXPP_OBJ_ATTR_SB_INSPRING,
EXPP_OBJ_ATTR_SB_INFRICT,
EXPP_OBJ_ATTR_EMPTY_DRAWTYPE
};
#define EXPP_OBJECT_DRAWSIZEMIN 0.01f
@ -2431,6 +2432,12 @@ static int Object_setDrawType( BPy_Object * self, PyObject * value )
OB_BOUNDBOX, OB_TEXTURE, 'b' );
}
static int Object_setEmptyShape( BPy_Object * self, PyObject * value )
{
return EXPP_setIValueRange( value, &self->object->empty_drawtype,
OB_ARROWS, OB_EMPTY_CONE, 'b' );
}
static int Object_setEuler( BPy_Object * self, PyObject * args )
{
float rot1, rot2, rot3;
@ -3758,6 +3765,9 @@ static PyObject *getIntAttr( BPy_Object *self, void *type )
case EXPP_OBJ_ATTR_DRAWTYPE:
param = object->dt;
break;
case EXPP_OBJ_ATTR_EMPTY_DRAWTYPE:
param = object->empty_drawtype;
break;
case EXPP_OBJ_ATTR_PARENT_TYPE:
param = object->partype;
break;
@ -4938,6 +4948,10 @@ static PyGetSetDef BPy_Object_getseters[] = {
(getter)getIntAttr, (setter)Object_setDrawType,
"The object's drawing type",
(void *)EXPP_OBJ_ATTR_DRAWTYPE},
{"emptyShape",
(getter)getIntAttr, (setter)Object_setEmptyShape,
"The empty's drawing shape",
(void *)EXPP_OBJ_ATTR_EMPTY_DRAWTYPE},
{"parentType",
(getter)getIntAttr, (setter)NULL,
"The object's parent type",
@ -5538,6 +5552,24 @@ static PyObject *M_Object_IpoKeyTypesDict( void )
return M;
}
static PyObject *M_Object_EmptyShapesDict( void )
{
PyObject *M = PyConstant_New( );
if( M ) {
BPy_constant *d = ( BPy_constant * ) M;
PyConstant_Insert( d, "ARROWS", PyInt_FromLong( OB_ARROWS ) );
PyConstant_Insert( d, "AXES", PyInt_FromLong( OB_PLAINAXES ) );
PyConstant_Insert( d, "CIRCLE", PyInt_FromLong( OB_CIRCLE ) );
PyConstant_Insert( d, "ARROW", PyInt_FromLong( OB_SINGLE_ARROW ) );
PyConstant_Insert( d, "CUBE", PyInt_FromLong( OB_CUBE ) );
PyConstant_Insert( d, "SPHERE", PyInt_FromLong( OB_EMPTY_SPHERE ) );
PyConstant_Insert( d, "CONE", PyInt_FromLong( OB_EMPTY_CONE ) );
}
return M;
}
/*****************************************************************************/
/* Function: initObject */
/*****************************************************************************/
@ -5552,6 +5584,7 @@ PyObject *Object_Init( void )
PyObject *RBFlagsDict = M_Object_RBFlagsDict( );
PyObject *RBShapesDict = M_Object_RBShapeBoundDict( );
PyObject *IpoKeyTypesDict = M_Object_IpoKeyTypesDict( );
PyObject *EmptyShapesDict = M_Object_EmptyShapesDict( );
PyType_Ready( &Object_Type ) ;
@ -5596,7 +5629,9 @@ PyObject *Object_Init( void )
if( RBShapesDict )
PyModule_AddObject( module, "RBShapes", RBShapesDict );
if( IpoKeyTypesDict )
PyModule_AddObject( module, "IpoKeyTypes", IpoKeyTypesDict );
PyModule_AddObject( module, "IpoKeyTypes", IpoKeyTypesDict );
if( EmptyShapesDict )
PyModule_AddObject( module, "EmptyShapes", EmptyShapesDict );
/*Add SUBMODULES to the module*/
dict = PyModule_GetDict( module ); /*borrowed*/

@ -117,6 +117,10 @@ Example::
attribute. Only one type can be selected at a time. Values are
BOX, SPHERE, CYLINDER, CONE, and POLYHEDERON
@type EmptyShapes: readonly dictionary
@var EmptyShapes: Constant dict used for with L{Object.emptyShape} attribute.
Only one type can be selected at a time. Values are
ARROW, ARROWS, AXES, CIRCLE, CONE, CUBE AND SPHERE
"""
def New (type, name='type'):
@ -347,7 +351,7 @@ class Object:
ob.layers = [] # object won't be visible
ob.layers = [1, 4] # object visible only in layers 1 and 4
ls = o.layers
ls.append([10])
ls.append(10)
o.layers = ls
print ob.layers # will print: [1, 4, 10]
B{Note}: changes will only be visible after the screen (at least
@ -525,6 +529,8 @@ class Object:
@ivar drawType: The object's drawing type.
See L{DrawTypes} constant dict for values.
@type drawType: int
@ivar emptyShape: The empty drawing shape.
See L{EmptyShapes} constant dict for values.
@ivar parentType: The object's parent type. Read-only.
See L{ParentTypes} constant dict for values.
@type parentType: int