bmesh py api: functions to add/renmove customdata layers, eg.

bm.loops.layers.color.new("Testing")
This commit is contained in:
2012-04-23 14:52:28 +00:00
parent f665c3cb00
commit 4c873fec53
2 changed files with 80 additions and 8 deletions

View File

@@ -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}
};