Skip to content

Commit

Permalink
add supporting node presets in group trees
Browse files Browse the repository at this point in the history
  • Loading branch information
Durman committed Jun 3, 2021
1 parent 5bf433d commit b531114
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ui/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def description(cls, context, properties):
return "Load node settings from the preset `{}' (overwrite current settings)".format(properties.preset_name)

def execute(self, context):
ntree = context.space_data.node_tree
ntree = context.space_data.path[-1].node_tree # in case if the node in a node group
node = ntree.nodes[self.node_name]
id_tree = ntree.name
ng = bpy.data.node_groups[id_tree]
Expand Down
9 changes: 8 additions & 1 deletion utils/sv_json_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
from abc import abstractmethod, ABC
from enum import Enum, auto
from itertools import chain
from typing import Type, Generator, TYPE_CHECKING, Dict, Tuple, Optional, List, Any

import bpy
Expand Down Expand Up @@ -73,7 +74,7 @@ def grab_from_module(cls) -> StructFactory:
module_classes = inspect.getmembers(sys.modules[__name__],
lambda member: inspect.isclass(member) and member.__module__ == __name__)
for class_name, module_class in module_classes:
if hasattr(module_class, 'type') and module_class.type in StrTypes:
if hasattr(module_class, 'type') and isinstance(module_class.type, StrTypes):
factory_classes.append(module_class)
return cls(factory_classes)

Expand Down Expand Up @@ -363,6 +364,12 @@ def build(self, node):
for node in tree.nodes:
imported_structs[StrTypes.NODE, tree.name, node.name] = node.name

# in case the node is inside group tree it should be also imported with its sockets
# to be able connect links to group out/in nodes
imported_structs[StrTypes.TREE, '', tree.name] = tree.name
for sock in chain(tree.inputs, tree.outputs):
imported_structs[StrTypes.INTERFACE, tree.name, sock.identifier] = sock.identifier

# import the node and rebuild the links if possible
node_struct.build(node, factories, imported_structs)
node.location = location # return to initial position, it has to be after node build
Expand Down

0 comments on commit b531114

Please sign in to comment.