[Bf-python] Generic Lib assign function problem.
Campbell Barton
cbarton at metavr.com
Mon Mar 5 02:33:49 CET 2007
Hi, Id like to make an generic assignment func.
so data with an ID can be assigned easerly
exampels are assigning an IPO to an object. texMesh to a mesh, world to
a scene.
I came up with
int GenericLib_assignData(PyObject *value, void **data, short refcount,
short type, short subtype)
It checks teh pyType is correct and assigns, or sets to NULL with
Py_None as well as optionaly adjusting the refcount.
But Im having problems setting the pointer...
Does anyone know how to set a pointer of a struct, outside the main function
Eg.
set_mesh(void **data, Mesh *me)
{
*data = me
}
.... somewhere else..
set_mesh(&me->texcomesh, some_mesh)
Iv tried quite a few different things but no luck.
Heres the functions.
/* returns the Blender lib type code from a PyObject
-1 for no match, only give this function libdata */
short GenericLib_getType(PyObject * pydata)
{
if (BPy_Scene_Check(pydata)) return ID_SCE;
if (BPy_Object_Check(pydata)) return ID_OB;
if (BPy_Mesh_Check(pydata)) return ID_ME;
if (BPy_Curve_Check(pydata)) return ID_CU;
if (BPy_Metaball_Check(pydata)) return ID_MB;
if (BPy_Material_Check(pydata)) return ID_MA;
if (BPy_Texture_Check(pydata)) return ID_TE;
if (BPy_Image_Check(pydata)) return ID_IM;
//if (BPy_Lattice_Check(pydata)) return ID_LT;
if (BPy_Lamp_Check(pydata)) return ID_LA;
if (BPy_Camera_Check(pydata)) return ID_CA;
if (BPy_Ipo_Check(pydata)) return ID_IP;
if (BPy_World_Check(pydata)) return ID_WO;
//if (BPy_Font_Check(pydata)) return ID_VF;
if (BPy_Text_Check(pydata)) return ID_TXT;
if (BPy_Sound_Check(pydata)) return ID_SO;
if (BPy_Group_Check(pydata)) return ID_GR;
if (BPy_Armature_Check(pydata)) return ID_AR;
if (BPy_Action_Check(pydata)) return ID_AC;
return -1;
}
int GenericLib_assignData(PyObject *value, void **data, short refcount,
short type, short subtype)
{
ID *id=NULL;
if (*data)
id = ((ID*)*data);
if (value == Py_None) {
*data = NULL;
if (refcount && id) id->us--;
} else if (GenericLib_getType(value) == type) {
/* object subtypes */
if (subtype != 0 && type == ID_OB) {
Object *ob = Object_FromPyObject(value);
if (ob->type != subtype) {
return EXPP_ReturnIntError( PyExc_TypeError,
"Object type not supported" );
}
}
if (refcount && id) id->us--;
id = ((BPy_GenericLib *)value)->id;
id->us++;
*data = id;
} else {
return EXPP_ReturnIntError( PyExc_TypeError,
"Could not assign Python Type - None or Library Object" );
}
return 0;
}
--
See MetaVR Visuals Used at the Combat Studies Institute
http://www.metavr.com/casestudies/baghdadviews.html
Campbell J Barton
133 Hope Street
Geelong West, Victoria 3218 Australia
URL: http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241
More information about the Bf-python
mailing list