[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45882] trunk/blender/source/blender: bmesh py api: functions to add/renmove customdata layers, eg.
Campbell Barton
ideasman42 at gmail.com
Mon Apr 23 16:52:28 CEST 2012
Revision: 45882
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45882
Author: campbellbarton
Date: 2012-04-23 14:52:28 +0000 (Mon, 23 Apr 2012)
Log Message:
-----------
bmesh py api: functions to add/renmove customdata layers, eg.
bm.loops.layers.color.new("Testing")
Modified Paths:
--------------
trunk/blender/source/blender/editors/mesh/editmesh_tools.c
trunk/blender/source/blender/python/bmesh/bmesh_py_types_customdata.c
Modified: trunk/blender/source/blender/editors/mesh/editmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_tools.c 2012-04-23 11:36:40 UTC (rev 45881)
+++ trunk/blender/source/blender/editors/mesh/editmesh_tools.c 2012-04-23 14:52:28 UTC (rev 45882)
@@ -4266,7 +4266,7 @@
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
- RNA_def_boolean(ot->srna, "use_boundary", TRUE, "Boundary", "Inset face boundries");
+ RNA_def_boolean(ot->srna, "use_boundary", TRUE, "Boundary", "Inset face boundaries");
RNA_def_boolean(ot->srna, "use_even_offset", TRUE, "Offset Even", "Scale the offset to give more even thickness");
RNA_def_boolean(ot->srna, "use_relative_offset", FALSE, "Offset Relative", "Scale the offset by surrounding geometry");
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_types_customdata.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_types_customdata.c 2012-04-23 11:36:40 UTC (rev 45881)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_types_customdata.c 2012-04-23 14:52:28 UTC (rev 45882)
@@ -216,6 +216,82 @@
/* 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 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}
};
More information about the Bf-blender-cvs
mailing list