diff --git a/core/node.py b/core/node.py index c5945df..503c026 100644 --- a/core/node.py +++ b/core/node.py @@ -18,6 +18,7 @@ class Node: self.parameters = [] self._parent = None + self._scene = None for prop in self.bl_node.bl_rna.properties: if prop.is_readonly: @@ -82,6 +83,32 @@ class Node: if self._parent: self.bl_node.parent = self._parent.bl_node + @property + def scene(self): + """Get the name of the scene used by the node. + + Returns: + str: scene name. + """ + if self._scene: + return self._scene.name + + @scene.setter + def scene(self, value): + """Set the blender scene using the bpy Scene object or its name. + + Args: + value (str|bpy.types.Scene): scene name or scene object to set th the node. + """ + if isinstance(value, str): + self._scene = bpy.data.scenes[value] + + elif isinstance(value, bpy.types.Scene): + self._scene = value + + if self._scene: + self.bl_node.scene = self._scene + @classmethod def from_dict(cls, data, tree): """Create all nodes from their dict representation. @@ -102,7 +129,7 @@ class Node: setattr(node, p, data[p]) # set attribute on the blender node only if correct type is retrieve - if p not in ('parent',): + if p not in ('parent', 'scene'): setattr(node.bl_node, p, getattr(node, p)) node.inputs = [Input.from_dict(ipt_data, node) for ipt_data in data['inputs'].values()]