2012-08-08 16:44:16 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
|
|
|
# <pep8-80 compliant>
|
|
|
|
|
2013-06-27 03:05:19 +00:00
|
|
|
import bpy
|
|
|
|
import nodeitems_utils
|
|
|
|
from bpy.types import (Operator,
|
|
|
|
PropertyGroup,
|
|
|
|
)
|
|
|
|
from bpy.props import (BoolProperty,
|
|
|
|
CollectionProperty,
|
|
|
|
EnumProperty,
|
|
|
|
IntProperty,
|
|
|
|
StringProperty,
|
|
|
|
)
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-01-15 23:15:32 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
class NodeSetting(PropertyGroup):
|
|
|
|
value = StringProperty(
|
|
|
|
name="Value",
|
|
|
|
description="Python expression to be evaluated as the initial node setting",
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2013-06-27 03:05:19 +00:00
|
|
|
|
2012-12-12 12:50:43 +00:00
|
|
|
# Base class for node 'Add' operators
|
|
|
|
class NodeAddOperator():
|
2013-05-08 15:40:53 +00:00
|
|
|
|
|
|
|
type = StringProperty(
|
|
|
|
name="Node Type",
|
|
|
|
description="Node type",
|
|
|
|
)
|
|
|
|
use_transform = BoolProperty(
|
|
|
|
name="Use Transform",
|
|
|
|
description="Start transform operator after inserting the node",
|
|
|
|
default=False,
|
|
|
|
)
|
|
|
|
settings = CollectionProperty(
|
|
|
|
name="Settings",
|
|
|
|
description="Settings to be applied on the newly created node",
|
|
|
|
type=NodeSetting,
|
2013-05-09 10:13:13 +00:00
|
|
|
options={'SKIP_SAVE'},
|
2013-05-08 15:40:53 +00:00
|
|
|
)
|
|
|
|
|
2012-12-12 12:50:43 +00:00
|
|
|
@staticmethod
|
|
|
|
def store_mouse_cursor(context, event):
|
|
|
|
space = context.space_data
|
2013-04-04 15:10:52 +00:00
|
|
|
tree = space.edit_tree
|
2012-12-12 12:50:43 +00:00
|
|
|
|
|
|
|
# convert mouse position to the View2D for later node placement
|
2013-04-04 15:10:52 +00:00
|
|
|
if context.region.type == 'WINDOW':
|
2013-09-05 13:03:03 +00:00
|
|
|
# convert mouse position to the View2D for later node placement
|
2013-09-18 00:07:17 +00:00
|
|
|
space.cursor_location_from_region(event.mouse_region_x, event.mouse_region_y)
|
2013-04-04 15:10:52 +00:00
|
|
|
else:
|
|
|
|
space.cursor_location = tree.view_center
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-05-09 11:43:48 +00:00
|
|
|
# XXX explicit node_type argument is usually not necessary, but required to make search operator work:
|
|
|
|
# add_search has to override the 'type' property since it's hardcoded in bpy_operator_wrap.c ...
|
|
|
|
def create_node(self, context, node_type=None):
|
2012-12-12 12:50:43 +00:00
|
|
|
space = context.space_data
|
|
|
|
tree = space.edit_tree
|
|
|
|
|
2013-05-09 11:43:48 +00:00
|
|
|
if node_type is None:
|
|
|
|
node_type = self.type
|
|
|
|
|
2012-12-12 12:50:43 +00:00
|
|
|
# select only the new node
|
|
|
|
for n in tree.nodes:
|
2012-12-12 15:41:15 +00:00
|
|
|
n.select = False
|
|
|
|
|
2013-05-09 11:43:48 +00:00
|
|
|
node = tree.nodes.new(type=node_type)
|
2013-05-08 15:40:53 +00:00
|
|
|
|
|
|
|
for setting in self.settings:
|
|
|
|
# XXX catch exceptions here?
|
|
|
|
value = eval(setting.value)
|
2013-06-27 03:05:19 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
try:
|
|
|
|
setattr(node, setting.name, value)
|
|
|
|
except AttributeError as e:
|
2013-06-27 03:05:19 +00:00
|
|
|
self.report({'ERROR_INVALID_INPUT'}, "Node has no attribute " + setting.name)
|
|
|
|
print(str(e))
|
2013-05-08 15:40:53 +00:00
|
|
|
# Continue despite invalid attribute
|
2012-12-12 15:41:15 +00:00
|
|
|
|
|
|
|
node.select = True
|
2012-12-12 12:50:43 +00:00
|
|
|
tree.nodes.active = node
|
|
|
|
node.location = space.cursor_location
|
|
|
|
return node
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
# needs active node editor and a tree to add nodes to
|
2013-06-05 19:06:33 +00:00
|
|
|
return (space.type == 'NODE_EDITOR' and space.edit_tree and not space.edit_tree.library)
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
# Default execute simply adds a node
|
|
|
|
def execute(self, context):
|
2013-10-06 10:49:40 +00:00
|
|
|
if self.properties.is_property_set("type"):
|
|
|
|
self.create_node(context)
|
|
|
|
return {'FINISHED'}
|
|
|
|
else:
|
|
|
|
return {'CANCELLED'}
|
2013-05-08 15:40:53 +00:00
|
|
|
|
2012-12-12 12:50:43 +00:00
|
|
|
# Default invoke stores the mouse position to place the node correctly
|
2013-05-08 15:40:53 +00:00
|
|
|
# and optionally invokes the transform operator
|
2012-12-12 12:50:43 +00:00
|
|
|
def invoke(self, context, event):
|
|
|
|
self.store_mouse_cursor(context, event)
|
2013-05-08 15:40:53 +00:00
|
|
|
result = self.execute(context)
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
if self.use_transform and ('FINISHED' in result):
|
2013-09-17 13:07:48 +00:00
|
|
|
# removes the node again if transform is cancelled
|
2013-09-18 00:07:17 +00:00
|
|
|
bpy.ops.transform.translate('INVOKE_DEFAULT', remove_on_cancel=True)
|
2013-05-08 15:40:53 +00:00
|
|
|
|
|
|
|
return result
|
2012-12-12 12:50:43 +00:00
|
|
|
|
Replacing the node Add menu and making the toolbar useful
As some people have already noticed, the "Add" menu for nodes is a bit messy since pynodes merge. The reason for this is that the order of nodes in submenus (categories) was previously defined by the order in which all nodes are registered (at the bottom of blenkernel/intern/node.c). For the dynamic registration of node types now possible this system of defining node order along with registration is no longer viable: while it would still sort of work for C nodes, it is completely meaningless for dynamic (python) nodes, which are basically registered automatically in whatever order modules and addons are loaded, with the added complexity of unloading and reloading.
To fix this problem and add a bunch of desirable features this commit replaces the C menu with a python implementation. The new menu does not rely on any particular order of types in the node registry, but instead uses a simple explicit list of all the available nodes, grouped by categories (in scripts/nodeitems_builtins.py).
There are a number of additional features that become possible with this implementation:
1) Node Toolbar can be populated!
The list of nodes is used to create 2 UI items for each node: 1 entry in a submenu of "Add" menu and 1 item in a node toolbar panel with basically the same functionality. Clicking a button in the toolbar will add a new node of this type, just like selecting an item in the menu. The toolbar has the advantage of having collapsible panels for each category, so users can decide if they don't need certain nodes categories and have the rest more easily accessible.
2) Each node item is a true operator call.
The old Add menu is a pretty old piece of C code which doesn't even use proper operator buttons. Now there is a generic node_add operator which can be used very flexibly for adding any of the available nodes.
3) Node Items support additional settings.
Each "NodeItem" consists of the basic node type plus an optional list of initial settings that shall be applied to a new instance. This gives additional flexibility for creating variants of the same node or for defining preferred initial settings. E.g. it has been requested to disable previews for all nodes except inputs, this would be simple change in the py code and much less intrusive than in C.
4) Node items can be generated with a function.
A callback can be used in any category instead of the fixed list, which generates a set of items based on the context (much like dynamic enum items in bpy.props). Originally this was implemented for group nodes, because these nodes only make sense when linked to a node tree from the library data. This principle could come in handy for a number of other nodes, e.g. Image nodes could provide a similar list of node variants based on images in the library - no need to first add node, then select an image.
WARNING: pynodes scripters will have to rework their "draw_add_menu" callback in node tree types, this has been removed now! It was already pretty redundant, since one can add draw functions to the Add menu just like for any other menu. In the future i'd like to improve the categories system further so scripters can use it for custom node systems too, for now just make a draw callback and attach it to the Add menu.
2013-04-13 15:38:02 +00:00
|
|
|
|
2012-12-12 12:50:43 +00:00
|
|
|
# Simple basic operator for adding a node
|
|
|
|
class NODE_OT_add_node(NodeAddOperator, Operator):
|
|
|
|
'''Add a node to the active tree'''
|
|
|
|
bl_idname = "node.add_node"
|
|
|
|
bl_label = "Add Node"
|
2013-05-10 09:54:25 +00:00
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
|
|
|
|
# Add a node and link it to an existing socket
|
|
|
|
class NODE_OT_add_and_link_node(NodeAddOperator, Operator):
|
|
|
|
'''Add a node to the active tree and link to an existing socket'''
|
|
|
|
bl_idname = "node.add_and_link_node"
|
|
|
|
bl_label = "Add and Link Node"
|
2013-05-10 09:54:25 +00:00
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2013-05-08 15:40:53 +00:00
|
|
|
|
|
|
|
link_socket_index = IntProperty(
|
|
|
|
name="Link Socket Index",
|
|
|
|
description="Index of the socket to link",
|
Replacing the node Add menu and making the toolbar useful
As some people have already noticed, the "Add" menu for nodes is a bit messy since pynodes merge. The reason for this is that the order of nodes in submenus (categories) was previously defined by the order in which all nodes are registered (at the bottom of blenkernel/intern/node.c). For the dynamic registration of node types now possible this system of defining node order along with registration is no longer viable: while it would still sort of work for C nodes, it is completely meaningless for dynamic (python) nodes, which are basically registered automatically in whatever order modules and addons are loaded, with the added complexity of unloading and reloading.
To fix this problem and add a bunch of desirable features this commit replaces the C menu with a python implementation. The new menu does not rely on any particular order of types in the node registry, but instead uses a simple explicit list of all the available nodes, grouped by categories (in scripts/nodeitems_builtins.py).
There are a number of additional features that become possible with this implementation:
1) Node Toolbar can be populated!
The list of nodes is used to create 2 UI items for each node: 1 entry in a submenu of "Add" menu and 1 item in a node toolbar panel with basically the same functionality. Clicking a button in the toolbar will add a new node of this type, just like selecting an item in the menu. The toolbar has the advantage of having collapsible panels for each category, so users can decide if they don't need certain nodes categories and have the rest more easily accessible.
2) Each node item is a true operator call.
The old Add menu is a pretty old piece of C code which doesn't even use proper operator buttons. Now there is a generic node_add operator which can be used very flexibly for adding any of the available nodes.
3) Node Items support additional settings.
Each "NodeItem" consists of the basic node type plus an optional list of initial settings that shall be applied to a new instance. This gives additional flexibility for creating variants of the same node or for defining preferred initial settings. E.g. it has been requested to disable previews for all nodes except inputs, this would be simple change in the py code and much less intrusive than in C.
4) Node items can be generated with a function.
A callback can be used in any category instead of the fixed list, which generates a set of items based on the context (much like dynamic enum items in bpy.props). Originally this was implemented for group nodes, because these nodes only make sense when linked to a node tree from the library data. This principle could come in handy for a number of other nodes, e.g. Image nodes could provide a similar list of node variants based on images in the library - no need to first add node, then select an image.
WARNING: pynodes scripters will have to rework their "draw_add_menu" callback in node tree types, this has been removed now! It was already pretty redundant, since one can add draw functions to the Add menu just like for any other menu. In the future i'd like to improve the categories system further so scripters can use it for custom node systems too, for now just make a draw callback and attach it to the Add menu.
2013-04-13 15:38:02 +00:00
|
|
|
)
|
2013-01-15 23:15:32 +00:00
|
|
|
|
2012-12-12 12:50:43 +00:00
|
|
|
def execute(self, context):
|
2013-05-08 15:40:53 +00:00
|
|
|
space = context.space_data
|
|
|
|
ntree = space.edit_tree
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
node = self.create_node(context)
|
|
|
|
if not node:
|
|
|
|
return {'CANCELLED'}
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
to_socket = getattr(context, "link_to_socket", None)
|
|
|
|
if to_socket:
|
|
|
|
ntree.links.new(node.outputs[self.link_socket_index], to_socket)
|
Replacing the node Add menu and making the toolbar useful
As some people have already noticed, the "Add" menu for nodes is a bit messy since pynodes merge. The reason for this is that the order of nodes in submenus (categories) was previously defined by the order in which all nodes are registered (at the bottom of blenkernel/intern/node.c). For the dynamic registration of node types now possible this system of defining node order along with registration is no longer viable: while it would still sort of work for C nodes, it is completely meaningless for dynamic (python) nodes, which are basically registered automatically in whatever order modules and addons are loaded, with the added complexity of unloading and reloading.
To fix this problem and add a bunch of desirable features this commit replaces the C menu with a python implementation. The new menu does not rely on any particular order of types in the node registry, but instead uses a simple explicit list of all the available nodes, grouped by categories (in scripts/nodeitems_builtins.py).
There are a number of additional features that become possible with this implementation:
1) Node Toolbar can be populated!
The list of nodes is used to create 2 UI items for each node: 1 entry in a submenu of "Add" menu and 1 item in a node toolbar panel with basically the same functionality. Clicking a button in the toolbar will add a new node of this type, just like selecting an item in the menu. The toolbar has the advantage of having collapsible panels for each category, so users can decide if they don't need certain nodes categories and have the rest more easily accessible.
2) Each node item is a true operator call.
The old Add menu is a pretty old piece of C code which doesn't even use proper operator buttons. Now there is a generic node_add operator which can be used very flexibly for adding any of the available nodes.
3) Node Items support additional settings.
Each "NodeItem" consists of the basic node type plus an optional list of initial settings that shall be applied to a new instance. This gives additional flexibility for creating variants of the same node or for defining preferred initial settings. E.g. it has been requested to disable previews for all nodes except inputs, this would be simple change in the py code and much less intrusive than in C.
4) Node items can be generated with a function.
A callback can be used in any category instead of the fixed list, which generates a set of items based on the context (much like dynamic enum items in bpy.props). Originally this was implemented for group nodes, because these nodes only make sense when linked to a node tree from the library data. This principle could come in handy for a number of other nodes, e.g. Image nodes could provide a similar list of node variants based on images in the library - no need to first add node, then select an image.
WARNING: pynodes scripters will have to rework their "draw_add_menu" callback in node tree types, this has been removed now! It was already pretty redundant, since one can add draw functions to the Add menu just like for any other menu. In the future i'd like to improve the categories system further so scripters can use it for custom node systems too, for now just make a draw callback and attach it to the Add menu.
2013-04-13 15:38:02 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
from_socket = getattr(context, "link_from_socket", None)
|
|
|
|
if from_socket:
|
|
|
|
ntree.links.new(from_socket, node.inputs[self.link_socket_index])
|
Replacing the node Add menu and making the toolbar useful
As some people have already noticed, the "Add" menu for nodes is a bit messy since pynodes merge. The reason for this is that the order of nodes in submenus (categories) was previously defined by the order in which all nodes are registered (at the bottom of blenkernel/intern/node.c). For the dynamic registration of node types now possible this system of defining node order along with registration is no longer viable: while it would still sort of work for C nodes, it is completely meaningless for dynamic (python) nodes, which are basically registered automatically in whatever order modules and addons are loaded, with the added complexity of unloading and reloading.
To fix this problem and add a bunch of desirable features this commit replaces the C menu with a python implementation. The new menu does not rely on any particular order of types in the node registry, but instead uses a simple explicit list of all the available nodes, grouped by categories (in scripts/nodeitems_builtins.py).
There are a number of additional features that become possible with this implementation:
1) Node Toolbar can be populated!
The list of nodes is used to create 2 UI items for each node: 1 entry in a submenu of "Add" menu and 1 item in a node toolbar panel with basically the same functionality. Clicking a button in the toolbar will add a new node of this type, just like selecting an item in the menu. The toolbar has the advantage of having collapsible panels for each category, so users can decide if they don't need certain nodes categories and have the rest more easily accessible.
2) Each node item is a true operator call.
The old Add menu is a pretty old piece of C code which doesn't even use proper operator buttons. Now there is a generic node_add operator which can be used very flexibly for adding any of the available nodes.
3) Node Items support additional settings.
Each "NodeItem" consists of the basic node type plus an optional list of initial settings that shall be applied to a new instance. This gives additional flexibility for creating variants of the same node or for defining preferred initial settings. E.g. it has been requested to disable previews for all nodes except inputs, this would be simple change in the py code and much less intrusive than in C.
4) Node items can be generated with a function.
A callback can be used in any category instead of the fixed list, which generates a set of items based on the context (much like dynamic enum items in bpy.props). Originally this was implemented for group nodes, because these nodes only make sense when linked to a node tree from the library data. This principle could come in handy for a number of other nodes, e.g. Image nodes could provide a similar list of node variants based on images in the library - no need to first add node, then select an image.
WARNING: pynodes scripters will have to rework their "draw_add_menu" callback in node tree types, this has been removed now! It was already pretty redundant, since one can add draw functions to the Add menu just like for any other menu. In the future i'd like to improve the categories system further so scripters can use it for custom node systems too, for now just make a draw callback and attach it to the Add menu.
2013-04-13 15:38:02 +00:00
|
|
|
|
2013-05-08 15:40:53 +00:00
|
|
|
return {'FINISHED'}
|
2012-12-12 12:50:43 +00:00
|
|
|
|
2012-08-08 16:44:16 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
class NODE_OT_add_search(NodeAddOperator, Operator):
|
2012-08-08 16:44:16 +00:00
|
|
|
'''Add a node to the active tree'''
|
|
|
|
bl_idname = "node.add_search"
|
|
|
|
bl_label = "Search and Add Node"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
2013-05-29 11:55:35 +00:00
|
|
|
bl_property = "node_item"
|
|
|
|
|
|
|
|
_enum_item_hack = []
|
2012-08-08 16:44:16 +00:00
|
|
|
|
2013-05-09 11:43:48 +00:00
|
|
|
# Create an enum list from node items
|
|
|
|
def node_enum_items(self, context):
|
2013-05-29 11:55:35 +00:00
|
|
|
enum_items = NODE_OT_add_search._enum_item_hack
|
|
|
|
enum_items.clear()
|
|
|
|
|
2013-05-09 11:43:48 +00:00
|
|
|
for index, item in enumerate(nodeitems_utils.node_items_iter(context)):
|
2013-06-08 17:35:05 +00:00
|
|
|
if isinstance(item, nodeitems_utils.NodeItem):
|
|
|
|
nodetype = getattr(bpy.types, item.nodetype, None)
|
|
|
|
if nodetype:
|
|
|
|
enum_items.append((str(index), item.label, nodetype.bl_rna.description, index))
|
2013-05-09 11:43:48 +00:00
|
|
|
return enum_items
|
|
|
|
|
|
|
|
# Look up the item based on index
|
|
|
|
def find_node_item(self, context):
|
2013-05-29 11:55:35 +00:00
|
|
|
node_item = int(self.node_item)
|
2013-05-09 11:43:48 +00:00
|
|
|
for index, item in enumerate(nodeitems_utils.node_items_iter(context)):
|
2013-05-29 11:55:35 +00:00
|
|
|
if index == node_item:
|
2013-05-09 11:43:48 +00:00
|
|
|
return item
|
|
|
|
return None
|
2013-04-21 13:51:51 +00:00
|
|
|
|
2013-05-29 11:55:35 +00:00
|
|
|
node_item = EnumProperty(
|
2012-08-08 17:02:14 +00:00
|
|
|
name="Node Type",
|
|
|
|
description="Node type",
|
2013-05-09 11:43:48 +00:00
|
|
|
items=node_enum_items,
|
2012-08-08 17:02:14 +00:00
|
|
|
)
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
def execute(self, context):
|
2013-05-09 11:43:48 +00:00
|
|
|
item = self.find_node_item(context)
|
2013-05-29 11:55:35 +00:00
|
|
|
|
|
|
|
# no need to keep
|
|
|
|
self._enum_item_hack.clear()
|
2013-06-27 03:05:19 +00:00
|
|
|
|
2013-05-09 11:43:48 +00:00
|
|
|
if item:
|
|
|
|
# apply settings from the node item
|
|
|
|
for setting in item.settings.items():
|
|
|
|
ops = self.settings.add()
|
|
|
|
ops.name = setting[0]
|
|
|
|
ops.value = setting[1]
|
|
|
|
|
|
|
|
self.create_node(context, item.nodetype)
|
|
|
|
|
|
|
|
if self.use_transform:
|
2013-11-07 08:33:09 +00:00
|
|
|
bpy.ops.transform.translate('INVOKE_DEFAULT', remove_on_cancel=True)
|
2013-05-09 11:43:48 +00:00
|
|
|
|
|
|
|
return {'FINISHED'}
|
|
|
|
else:
|
|
|
|
return {'CANCELLED'}
|
2012-08-08 16:44:16 +00:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
def invoke(self, context, event):
|
|
|
|
self.store_mouse_cursor(context, event)
|
|
|
|
# Delayed execution in the search popup
|
|
|
|
context.window_manager.invoke_search_popup(self)
|
|
|
|
return {'CANCELLED'}
|
2012-08-08 17:02:14 +00:00
|
|
|
|
2012-08-10 07:22:36 +00:00
|
|
|
|
2012-08-14 17:56:33 +00:00
|
|
|
class NODE_OT_collapse_hide_unused_toggle(Operator):
|
|
|
|
'''Toggle collapsed nodes and hide unused sockets'''
|
|
|
|
bl_idname = "node.collapse_hide_unused_toggle"
|
|
|
|
bl_label = "Collapse and Hide Unused Sockets"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
# needs active node editor and a tree
|
2013-06-05 19:06:33 +00:00
|
|
|
return (space.type == 'NODE_EDITOR' and space.edit_tree and not space.edit_tree.library)
|
2012-08-14 17:56:33 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
space = context.space_data
|
|
|
|
tree = space.edit_tree
|
|
|
|
|
|
|
|
for node in tree.nodes:
|
|
|
|
if node.select:
|
2012-08-14 18:43:15 +00:00
|
|
|
hide = (not node.hide)
|
|
|
|
|
2012-08-14 17:56:33 +00:00
|
|
|
node.hide = hide
|
|
|
|
# Note: connected sockets are ignored internally
|
|
|
|
for socket in node.inputs:
|
|
|
|
socket.hide = hide
|
|
|
|
for socket in node.outputs:
|
|
|
|
socket.hide = hide
|
|
|
|
|
2012-08-14 18:43:15 +00:00
|
|
|
return {'FINISHED'}
|
2013-03-18 16:34:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NODE_OT_tree_path_parent(Operator):
|
|
|
|
'''Go to parent node tree'''
|
|
|
|
bl_idname = "node.tree_path_parent"
|
|
|
|
bl_label = "Parent Node Tree"
|
|
|
|
bl_options = {'REGISTER', 'UNDO'}
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def poll(cls, context):
|
|
|
|
space = context.space_data
|
|
|
|
# needs active node editor and a tree
|
|
|
|
return (space.type == 'NODE_EDITOR' and len(space.path) > 1)
|
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
space = context.space_data
|
|
|
|
|
|
|
|
space.path.pop()
|
|
|
|
|
|
|
|
return {'FINISHED'}
|