Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-04-23 18:52:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-04-23 18:52:28 +0400
commit4c873fec536bcb9c520b77265772281f939e27ba (patch)
tree9c1b970f831df98dcdd18ce19417e1317275e6e6 /source/blender/python/bmesh
parentf665c3cb00ed39b4cb1a50dd32f8facaf647039e (diff)
bmesh py api: functions to add/renmove customdata layers, eg.
bm.loops.layers.color.new("Testing")
Diffstat (limited to 'source/blender/python/bmesh')
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.c86
1 files changed, 79 insertions, 7 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index 5d9c07269e8..28252a98cf6 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -216,6 +216,82 @@ static PyGetSetDef bpy_bmlayeritem_getseters[] = {
/* BMLayerCollection
* ----------------- */
+
+PyDoc_STRVAR(bpy_bmlayercollection_new_doc,
+".. method:: new(name)\n"
+"\n"
+" Create a new layer\n"
+"\n"
+" :arg name: Optional name argument (will be made unique).\n"
+" :type name: string\n"
+" :return: The newly created layer.\n"
+" :rtype: :class:`BMLayerItem`\n"
+);
+static PyObject *bpy_bmlayercollection_new(BPy_BMLayerCollection *self, PyObject *args)
+{
+ const char *name = NULL;
+ int index;
+ CustomData *data;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "|s:new", &name)) {
+ return NULL;
+ }
+
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+
+ if (name) {
+ BM_data_layer_add_named(self->bm, data, self->type, name);
+ }
+ else {
+ BM_data_layer_add(self->bm, data, self->type);
+ }
+
+ index = CustomData_number_of_layers(data, self->type) - 1;
+ BLI_assert(index >= 0);
+
+ return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
+}
+
+PyDoc_STRVAR(bpy_bmlayercollection_remove_doc,
+".. method:: remove(layer)\n"
+"\n"
+" Remove a layer\n"
+"\n"
+" :arg layer: The layer to remove.\n"
+" :type layer: :class:`BMLayerItem`\n"
+);
+static PyObject *bpy_bmlayercollection_remove(BPy_BMLayerCollection *self, BPy_BMLayerItem *value)
+{
+ CustomData *data;
+
+ BPY_BM_CHECK_OBJ(self);
+
+ if (!BPy_BMLayerItem_Check(value)) {
+ PyErr_Format(PyExc_TypeError,
+ "layers.remove(x): expected BMLayerItem, not '%.200s'",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+
+ BPY_BM_CHECK_OBJ(value);
+
+ if ((self->bm != value->bm) ||
+ (self->type != value->type) ||
+ (self->htype != value->htype))
+ {
+ PyErr_SetString(PyExc_ValueError,
+ "layers.remove(x): x not in layers");
+ }
+
+ data = bpy_bm_customdata_get(self->bm, self->htype);
+ BM_data_layer_free_n(self->bm, data, self->type, value->index);
+
+ Py_RETURN_NONE;
+}
+
+
PyDoc_STRVAR(bpy_bmlayercollection_keys_doc,
".. method:: keys()\n"
"\n"
@@ -361,17 +437,13 @@ static PyObject *bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject
}
static struct PyMethodDef bpy_bmelemseq_methods[] = {
+ {"new", (PyCFunction)bpy_bmlayercollection_new, METH_VARARGS, bpy_bmlayercollection_new_doc},
+ {"remove", (PyCFunction)bpy_bmlayercollection_remove, METH_O, bpy_bmlayercollection_remove_doc},
+
{"keys", (PyCFunction)bpy_bmlayercollection_keys, METH_NOARGS, bpy_bmlayercollection_keys_doc},
{"values", (PyCFunction)bpy_bmlayercollection_values, METH_NOARGS, bpy_bmlayercollection_values_doc},
{"items", (PyCFunction)bpy_bmlayercollection_items, METH_NOARGS, bpy_bmlayercollection_items_doc},
{"get", (PyCFunction)bpy_bmlayercollection_get, METH_VARARGS, bpy_bmlayercollection_get_doc},
-
- /* for later! */
-#if 0
-
- {"new", (PyCFunction)bpy_bmlayercollection_new, METH_O, bpy_bmlayercollection_new_doc},
- {"remove", (PyCFunction)bpy_bmlayercollection_new, METH_O, bpy_bmlayercollection_remove_doc},
-#endif
{NULL, NULL, 0, NULL}
};