From 33da577d3459907b23324b747e4b8a5378eaa352 Mon Sep 17 00:00:00 2001 From: Joseph Gilbert Date: Mon, 17 Nov 2003 07:13:27 +0000 Subject: [PATCH] - added vgrouping methods for renaming a vertex group and returning all vgroup names --- source/blender/python/api2_2x/NMesh.c | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c index 28f89712fb0..1cd16afa70c 100644 --- a/source/blender/python/api2_2x/NMesh.c +++ b/source/blender/python/api2_2x/NMesh.c @@ -1066,6 +1066,8 @@ static struct PyMethodDef NMesh_methods[] = MethodDef(assignVertsToGroup), MethodDef(removeVertsFromGroup), MethodDef(getVertsFromGroup), + MethodDef(renameVertGroup), + MethodDef(getVertGroupNames), MethodDef(hasVertexColours), MethodDef(hasFaceUV), MethodDef(hasVertexUV), @@ -2214,6 +2216,7 @@ static PyObject *NMesh_addVertGroup (PyObject *self, PyObject *args) { char* groupStr; struct Object* object; + PyObject *tempStr; if (!PyArg_ParseTuple(args, "s", &groupStr)) return EXPP_ReturnPyObjError (PyExc_TypeError, @@ -2225,6 +2228,10 @@ static PyObject *NMesh_addVertGroup (PyObject *self, PyObject *args) object = ((BPy_NMesh*)self)->object; + //get clamped name + tempStr = PyString_FromStringAndSize(groupStr, 32); + groupStr = PyString_AsString(tempStr); + add_defgroup_name (object, groupStr); allqueue (REDRAWBUTSALL, 1); @@ -2567,3 +2574,52 @@ static PyObject *NMesh_getVertsFromGroup (PyObject *self, PyObject *args) return (vertexList); } + +static PyObject *NMesh_renameVertGroup (PyObject *self, PyObject *args) +{ + char * oldGr = NULL; + char * newGr = NULL; + bDeformGroup * defGroup = NULL; + PyObject *tempStr; + + + if(!((BPy_NMesh*)self)->object) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "This mesh must be linked to an object"); + + if (!PyArg_ParseTuple(args, "ss", &oldGr, &newGr)) + return EXPP_ReturnPyObjError (PyExc_TypeError, + "Expected string & string argument"); + + defGroup = get_named_vertexgroup(((BPy_NMesh*)self)->object, oldGr); + if(defGroup == NULL) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "Couldn't find the expected vertex group"); + + //set name + tempStr = PyString_FromStringAndSize(newGr, 32); + newGr = PyString_AsString(tempStr); + memcpy (defGroup->name, newGr, 32); + unique_vertexgroup_name(defGroup, ((BPy_NMesh*)self)->object); + + return EXPP_incr_ret (Py_None); +} + +static PyObject *NMesh_getVertGroupNames (PyObject *self, PyObject *args) +{ + bDeformGroup * defGroup; + PyObject *list; + + if(!((BPy_NMesh*)self)->object) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "This mesh must be linked to an object"); + + list = PyList_New(0); + for (defGroup = (((BPy_NMesh*)self)->object)->defbase.first; defGroup; defGroup=defGroup->next){ + if(PyList_Append(list,PyString_FromString(defGroup->name)) < 0) + return EXPP_ReturnPyObjError (PyExc_RuntimeError, + "Couldn't add item to list"); + } + + return list; +}