added fakeUser and users to more pytypes

This commit is contained in:
2006-12-17 02:16:29 +00:00
parent 6acadfe982
commit 1041ad4719
11 changed files with 113 additions and 64 deletions

View File

@@ -607,6 +607,29 @@ AttributeError:
return EXPP_ReturnIntError( PyExc_TypeError,
"expected a list of integers" );
}
//------------------------Armature.users (getter)
static PyObject *Armature_getUsers( BPy_Armature * self )
{
return PyInt_FromLong( self->armature->id.us );
}
//------------------------Armature.fakeUser (getter)
static PyObject *Armature_getFakeUser( BPy_Armature * self )
{
if (self->armature->id.flag & LIB_FAKEUSER)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
//------------------------Armature.fakeUser (setter)
static int Armature_setFakeUser( BPy_Armature * self, PyObject * value )
{
return SetIdFakeUser(&self->armature->id, value);
}
//------------------------Armature.mirrorEdit (getter)
static PyObject *Armature_getMirrorEdit(BPy_Armature *self, void *closure)
{
@@ -1001,6 +1024,10 @@ static PyGetSetDef BPy_Armature_getset[] = {
"Adds temporal IK chains while grabbing bones", NULL},
{"layers", (getter)Armature_getLayers, (setter)Armature_setLayers,
"List of layers for the armature", NULL},
{"users", (getter)Armature_getUsers, (setter)NULL,
"The number of object users", NULL},
{"fakeUser", (getter)Armature_getFakeUser, (setter)Armature_setFakeUser,
"The fake user status of this object", NULL},
{NULL, NULL, NULL, NULL, NULL}
};
//------------------------tp_new

View File

@@ -250,13 +250,24 @@ static PyObject *Group_getName( BPy_Group * self, PyObject * args )
static PyObject *Group_getUsers( BPy_Group * self )
{
GROUP_DEL_CHECK_PY(self);
return PyInt_FromLong( self->group->id.us );
}
static PyObject *Group_getFakeUser( BPy_Group * self )
{
GROUP_DEL_CHECK_PY(self);
if (self->group->id.flag & LIB_FAKEUSER)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
static int Group_setFakeUser( BPy_Group * self, PyObject * value )
{
GROUP_DEL_CHECK_PY(self);
return SetIdFakeUser(&self->group->id, value);
}
@@ -302,6 +313,10 @@ static PyGetSetDef BPy_Group_getseters[] = {
(getter)Group_getUsers, (setter)NULL,
"Number of group users",
NULL},
{"fakeUser",
(getter)Group_getFakeUser, (setter)Group_setFakeUser,
"Number of group users",
NULL},
{"layers",
(getter)Group_getLayers, (setter)Group_setLayers,
"Number of group users",

View File

@@ -2869,26 +2869,7 @@ static PyObject *Material_getFakeUser( BPy_Material * self )
static int Material_setFakeUser( BPy_Material * self, PyObject * value )
{
int param;
ID *id = &self->material->id;
param = PyObject_IsTrue( value );
if( param == -1 )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected int argument in range [0,1]" );
if (param) {
if (!(id->flag & LIB_FAKEUSER)) {
id->flag |= LIB_FAKEUSER;
id_us_plus(id);
}
} else {
if (id->flag & LIB_FAKEUSER) {
id->flag &= ~LIB_FAKEUSER;
id->us--;
}
}
return 0;
return SetIdFakeUser(&self->material->id, value);
}

View File

@@ -6954,26 +6954,7 @@ static PyObject *Mesh_getFakeUser( BPy_Mesh * self )
static int Mesh_setFakeUser( BPy_Mesh * self, PyObject * value )
{
int param;
ID *id = &self->mesh->id;
param = PyObject_IsTrue( value );
if( param == -1 )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected int argument in range [0,1]" );
if (param) {
if (!(id->flag & LIB_FAKEUSER)) {
id->flag |= LIB_FAKEUSER;
id_us_plus(id);
}
} else {
if (id->flag & LIB_FAKEUSER) {
id->flag &= ~LIB_FAKEUSER;
id->us--;
}
}
return 0;
return SetIdFakeUser(&self->mesh->id, value);
}
static PyObject *Mesh_getFlag( BPy_Mesh * self, void *type )

View File

@@ -118,6 +118,8 @@ static PyObject *Metaball_getThresh( BPy_Metaball * self );
static int Metaball_setThresh( BPy_Metaball * self, PyObject * args );
static PyObject *Metaball_copy( BPy_Metaball * self );
static PyObject *Metaball_getUsers( BPy_Metaball * self );
static PyObject *Metaball_getFakeUser( BPy_Metaball * self );
static int Metaball_setFakeUser( BPy_Metaball * self, PyObject * value );
/*****************************************************************************/
/* Python BPy_Metaball methods table: */
@@ -178,6 +180,10 @@ static PyGetSetDef BPy_Metaball_getseters[] = {
(getter)Metaball_getUsers, (setter)NULL,
"Number of metaball users",
NULL},
{"fakeUser",
(getter)Metaball_getFakeUser, (setter)Metaball_setFakeUser,
"The fake user status of this object",
NULL},
{"materials",
(getter)Metaball_getMaterials, (setter)Metaball_setMaterials,
"Number of metaball users",
@@ -698,6 +704,19 @@ static PyObject *Metaball_getUsers( BPy_Metaball * self )
return PyInt_FromLong( self->metaball->id.us );
}
static PyObject *Metaball_getFakeUser( BPy_Metaball * self )
{
if (self->metaball->id.flag & LIB_FAKEUSER)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
static int Metaball_setFakeUser( BPy_Metaball * self, PyObject * value )
{
return SetIdFakeUser(&self->metaball->id, value);
}
static PyObject *Metaball_copy( BPy_Metaball * self )

View File

@@ -4456,26 +4456,7 @@ static PyObject *Object_getFakeUser( BPy_Object * self )
static int Object_setFakeUser( BPy_Object * self, PyObject * value )
{
int param;
ID *id = &self->object->id;
param = PyObject_IsTrue( value );
if( param == -1 )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected int argument in range [0,1]" );
if (param) {
if (!(id->flag & LIB_FAKEUSER)) {
id->flag |= LIB_FAKEUSER;
id_us_plus(id);
}
} else {
if (id->flag & LIB_FAKEUSER) {
id->flag &= ~LIB_FAKEUSER;
id->us--;
}
}
return 0;
return SetIdFakeUser(&self->object->id, value);
}
/* Localspace matrix */

View File

@@ -161,6 +161,11 @@ class Armature:
@type mirrorEdit: Bool
@ivar autoIK: Adds temporary IK chains while grabbing bones
@type autoIK: Bool
@ivar users: The number of users of the armature. Read-only.
@type users: int
@ivar fakeUser: The fake user status.
enabling this will keep it in the blend even if there are no users.
@type fakeUser: bool
"""
def __init__(name = 'myArmature'):

View File

@@ -88,11 +88,18 @@ class Group:
================
This object gives access to Groups in Blender.
@ivar name: The name of this Group object.
@type name: string
@ivar users: Number of users this group has (read only)
@ivar layers: Layer mask for this group.
@type users: int
@ivar fakeUser: The fake user status.
enabling this will keep it in the blend even if there are no users.
@type fakeUser: bool
@ivar layers: Layer bitmask for this group.
@type layers: int
@ivar objects: Objects that this group uses.
This is a sequence with-list like access so use list(grp.objects) if you need to use a list (where grp is a group).
The groups objects can be set by assigning a list or iterator of objects to the groups objects.
objects.link() and objects.unlink() also work with the the objects iterator just like with lists.
@type objects: custom object sequence
"""

View File

@@ -131,6 +131,9 @@ class Metaball:
@type name: string
@ivar users: The user count (read only)
@type users: int
@ivar fakeUser: The fake user status.
enabling this will keep it in the blend even if there are no users.
@type fakeUser: bool
@ivar elements: Element iterator of MetaElemSeq type.
@type elements: MetaElemSeq
@ivar wiresize: display resolution.

View File

@@ -158,6 +158,34 @@ ID *GetIdFromList( ListBase * list, char *name )
return id;
}
/*****************************************************************************/
/* Description: This function sets the fake user status of the ID */
/* returns an int error, so from getsetattrs */
/*****************************************************************************/
int SetIdFakeUser( ID * id, PyObject *value)
{
int param;
param = PyObject_IsTrue( value );
if( param == -1 )
return EXPP_ReturnIntError( PyExc_TypeError,
"expected int argument in range [0,1]" );
if (param) {
if (!(id->flag & LIB_FAKEUSER)) {
id->flag |= LIB_FAKEUSER;
id_us_plus(id);
}
} else {
if (id->flag & LIB_FAKEUSER) {
id->flag &= ~LIB_FAKEUSER;
id->us--;
}
}
return 0;
}
/*****************************************************************************/
/* Description: These functions set an internal string with the given type */
/* and error_msg arguments. */

View File

@@ -66,6 +66,8 @@ PyObject *EXPP_GetModuleConstant(char *module, char *constant);
int StringEqual( const char *string1, const char *string2 );
char *GetIdName( ID * id );
int SetIdFakeUser( ID * id, PyObject *value);
ID *GetIdFromList( ListBase * list, char *name );
PyObject *PythonReturnErrorObject( PyObject * type, char *error_msg );