Commit: f23b20b58aa90a4dca15cc6f951b3a4ac975fbf9
Author: Sybren A. Stüvel
Date:   Fri Oct 14 16:35:19 2016 +0200
Branches: temp-sybren-bpy-make-local
https://developer.blender.org/rBf23b20b58aa90a4dca15cc6f951b3a4ac975fbf9

Added bpy.data.make_local() that can make a single ID block local.

Note that this will not work reliably when the idblock is referenced
from a library. It is the caller's responsibility to ensure a proper
state. Use with care.

===================================================================

M       release/scripts/modules/bpy_types.py
M       source/blender/python/intern/bpy_rna_id_collection.c

===================================================================

diff --git a/release/scripts/modules/bpy_types.py 
b/release/scripts/modules/bpy_types.py
index d64acd2..71705ff 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -28,6 +28,7 @@ StructMetaPropGroup = bpy_types.bpy_struct_meta_idprop
 bpy_types.BlendDataLibraries.load = _bpy._library_load
 bpy_types.BlendDataLibraries.write = _bpy._library_write
 bpy_types.BlendData.user_map = _bpy._rna_id_collection_user_map
+bpy_types.BlendData.make_local = _bpy._rna_id_collection_make_local
 
 
 class Context(StructRNA):
diff --git a/source/blender/python/intern/bpy_rna_id_collection.c 
b/source/blender/python/intern/bpy_rna_id_collection.c
index 1037c83..bf030eb 100644
--- a/source/blender/python/intern/bpy_rna_id_collection.c
+++ b/source/blender/python/intern/bpy_rna_id_collection.c
@@ -38,6 +38,7 @@
 #include "BKE_main.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
+#include "BKE_object.h"
 
 #include "DNA_ID.h"
 /* Those folowing are only to support hack of not listing some internal 
'backward' pointers in generated user_map... */
@@ -291,12 +292,61 @@ error:
 
 }
 
+PyDoc_STRVAR(bpy_make_local_doc,
+".. method:: make_local(idblock, clear_proxy=True)\n"
+"\n"
+"   Makes the given ID datablock local.\n"
+"\n"
+"   Note that this will not work reliably when the idblock is referenced from 
a library.\n"
+"   It is the caller's responsibility to ensure a proper state. Use with 
care.\n"
+"\n"
+"   :arg idblock: The data-blocks that will be made local.\n"
+"   :type idblock: bpy.types.ID\n"
+"   :arg clear_proxy: Whether to clear proxies (default) or not. Can cause 
proxies to be\n"
+"                     duplicated when still referred to from another 
library.\n"
+"   :type clear_proxy: bool\n"
+);
+static PyObject *bpy_make_local(PyObject *UNUSED(self), PyObject *args, 
PyObject *kwds)
+{
+       Main *bmain = G.main;  /* XXX see note in bpy_user_map() about this 
being ugly. */
+       ID *id;
+       static const char *kwlist[] = {"idblock", "clear_proxy", NULL};
+       PyObject *py_id;
+       bool clear_proxy=true;
+
+       if (!PyArg_ParseTupleAndKeywords(
+               args, kwds, "O|$p:make_local", (char **)kwlist,
+               &py_id, &clear_proxy))
+       {
+               return NULL;
+       }
+
+       if (!pyrna_id_FromPyObject(py_id, &id)) {
+               PyErr_SetString(PyExc_ValueError, "idblock parameter is not 
actually an ID datablock");
+               return NULL;
+       }
+
+       /* Special case, as we can't rely on id_make_local(); it clears 
proxies. */
+       if (!clear_proxy && GS(id->name) == ID_OB) {
+               BKE_object_make_local_ex(bmain, (Object *)id, false, 
clear_proxy);
+       }
+       else {
+               id_make_local(bmain, id, false, false);
+       }
+
+       Py_RETURN_NONE;
+}
+
+
 int BPY_rna_id_collection_module(PyObject *mod_par)
 {
        static PyMethodDef user_map = {
            "user_map", (PyCFunction)bpy_user_map, METH_VARARGS | 
METH_KEYWORDS, bpy_user_map_doc};
+       static PyMethodDef make_local_map = {
+           "make_local", (PyCFunction)bpy_make_local, METH_VARARGS | 
METH_KEYWORDS, bpy_make_local_doc};
 
        PyModule_AddObject(mod_par, "_rna_id_collection_user_map", 
PyCFunction_New(&user_map, NULL));
+       PyModule_AddObject(mod_par, "_rna_id_collection_make_local", 
PyCFunction_New(&make_local_map, NULL));
 
        return 0;
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to