===Python API===

Added activeGroup attribute to Mesh API, to get/set active vertex group for
meshes.
This commit is contained in:
Ken Hughes
2006-05-02 17:44:44 +00:00
parent 88f225f226
commit 9874d5c76f
2 changed files with 52 additions and 2 deletions

View File

@@ -6530,6 +6530,49 @@ static int Mesh_setActiveFace( BPy_Mesh * self, PyObject * value )
return 0;
}
static PyObject *Mesh_getActiveGroup( BPy_Mesh * self )
{
bDeformGroup *defGroup;
Object *object = self->object;
if( !object )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"This mesh must be linked to an object" );
if( object->actdef ) {
defGroup = BLI_findlink( &object->defbase, object->actdef-1 );
return PyString_FromString( defGroup->name );
}
Py_RETURN_NONE;
}
static int Mesh_setActiveGroup( BPy_Mesh * self, PyObject * arg )
{
char *name;
int tmp;
Object *object = self->object;
if( !object )
return EXPP_ReturnIntError( PyExc_RuntimeError,
"This mesh must be linked to an object" );
if( !PyString_Check( arg ) )
return EXPP_ReturnIntError( PyExc_AttributeError,
"expected a string argument" );
name = PyString_AsString( arg );
tmp = object->actdef;
vertexgroup_select_by_name( object, name );
if( !object->actdef ) {
object->actdef = tmp;
return EXPP_ReturnIntError( PyExc_ValueError,
"vertex group not found" );
}
return 0;
}
/************************************************************************
*
* Python Mesh_Type standard operations
@@ -6607,6 +6650,10 @@ static PyGetSetDef BPy_Mesh_getseters[] = {
(getter)Mesh_getUsers, (setter)NULL,
"Number of users of the mesh",
NULL},
{"activeGroup",
(getter)Mesh_getActiveGroup, (setter)Mesh_setActiveGroup,
"Active group for the mesh",
NULL},
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
};

View File

@@ -139,7 +139,7 @@ def Mode(mode=0):
Get and/or set the selection modes for mesh editing. These are the modes
visible in the 3D window when a mesh is in Edit Mode.
@type mode: int
@param mode: The name of the mesh data object. See L{SelectModes} for values.
@param mode: The desired selection mode. See L{SelectModes} for values.
Modes can be combined. If omitted, the selection mode is not changed.
@rtype: int
@return: the current selection mode.
@@ -643,6 +643,9 @@ class Mesh:
Will throw an exception if the mesh does not have UV faces; use
L{faceUV} to test.
@type activeFace: int
@ivar activeGroup: The mesh's active vertex group. The mesh must be
linked to an object (read the comment in L{addVertGroup} for more info).
@type activeGroup: string
"""
def getFromObject(name,cage=0):
@@ -741,7 +744,7 @@ class Mesh:
def addVertGroup(group):
"""
Add a named and empty vertex (deform) group to the object this nmesh is
Add a named and empty vertex (deform) group to the object this mesh is
linked to. The mesh must first be linked to an object (with object.link()
or object.getData() ) so the method knows which object to update.
This is because vertex groups in Blender are stored in I{the object} --