[Bf-blender-cvs] [98376bc8ee9] functions: automatically load node groups from nodelib

Jacques Lucke noreply at git.blender.org
Thu Dec 19 13:21:34 CET 2019


Commit: 98376bc8ee9391b272ce2c3fe20a9b65e2b38f83
Author: Jacques Lucke
Date:   Thu Dec 19 11:41:21 2019 +0100
Branches: functions
https://developer.blender.org/rB98376bc8ee9391b272ce2c3fe20a9b65e2b38f83

automatically load node groups from nodelib

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	release/scripts/startup/nodes/search.py
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 9527c7f4de8..7155e6f46e8 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1189,6 +1189,7 @@ class USERPREF_PT_file_paths_data(FilePathsPanel, Panel):
         col.prop(paths, "script_directory", text="Scripts")
         col.prop(paths, "sound_directory", text="Sounds")
         col.prop(paths, "temporary_directory", text="Temporary Files")
+        col.prop(paths, "nodelib_directory", text="Nodelib Files")
 
 
 class USERPREF_PT_file_paths_render(FilePathsPanel, Panel):
diff --git a/release/scripts/startup/nodes/search.py b/release/scripts/startup/nodes/search.py
index 0f6c36f8f15..d1e28e855f0 100644
--- a/release/scripts/startup/nodes/search.py
+++ b/release/scripts/startup/nodes/search.py
@@ -1,5 +1,6 @@
 import bpy
 from bpy.props import *
+from pathlib import Path
 from . base import BaseNode
 from . utils.enum_items_cache import cache_enum_items
 
@@ -22,6 +23,17 @@ class NodeSearch(bpy.types.Operator):
             item = encode_search_item(("EXISTING_GROUP", tree.name), "(G) " + tree.name)
             items.append(item)
 
+        local_group_names = set(tree.name for tree in bpy.data.node_groups)
+        nodelibdir = Path(context.preferences.filepaths.nodelib_directory)
+        for path in nodelibdir.glob("**/*"):
+            if not path.is_file():
+                continue
+            with bpy.data.libraries.load(str(path)) as (data_from, data_to):
+                for group_name in data_from.node_groups:
+                    if group_name not in local_group_names:
+                        item = encode_search_item(("LIB_GROUP", str(path), group_name), "(G) " + group_name)
+                        items.append(item)
+
         sorted_items = list(sorted(items, key=lambda item: item[1]))
         return sorted_items
 
@@ -55,6 +67,13 @@ class NodeSearch(bpy.types.Operator):
             bpy.ops.node.add_node('INVOKE_DEFAULT', type="fn_GroupNode")
             new_node = context.active_node
             new_node.node_group = bpy.data.node_groups[group_name]
+        elif item_type == "LIB_GROUP":
+            path, group_name = item_data[1:]
+            bpy.ops.node.add_node('INVOKE_DEFAULT', type="fn_GroupNode")
+            new_node = context.active_node
+            with bpy.data.libraries.load(path, link=True) as (data_from, data_to):
+                data_to.node_groups = [group_name]
+            new_node.node_group = bpy.data.node_groups[group_name]
 
         bpy.ops.node.translate_attach("INVOKE_DEFAULT")
         return {'FINISHED'}
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 1f92b134e4c..c01fb7753d4 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -626,6 +626,7 @@ typedef struct UserDef {
   /** FILE_MAXDIR length. */
   char tempdir[768];
   char fontdir[768];
+  char nodelibdir[768];
   /** FILE_MAX length. */
   char renderdir[1024];
   /* EXR cache path */
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index ed89faf69cf..c4472ed1d1e 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -5790,6 +5790,13 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
       prop, "Temporary Directory", "The directory for storing temporary save files");
   RNA_def_property_update(prop, 0, "rna_userdef_temp_update");
 
+  prop = RNA_def_property(srna, "nodelib_directory", PROP_STRING, PROP_DIRPATH);
+  RNA_def_property_string_sdna(prop, NULL, "nodelibdir");
+  RNA_def_property_ui_text(
+      prop,
+      "Nodelib Directory",
+      "All node groups in .blend files in this directory can be loaded easily");
+
   prop = RNA_def_property(srna, "render_cache_directory", PROP_STRING, PROP_DIRPATH);
   RNA_def_property_string_sdna(prop, NULL, "render_cachedir");
   RNA_def_property_ui_text(prop, "Render Cache Path", "Where to cache raw render results");



More information about the Bf-blender-cvs mailing list