[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4374] contrib/py/scripts/addons/ node_efficiency_tools.py: change of several operators.
Bartek Skorupa
bartekskorupa at bartekskorupa.com
Thu Mar 14 18:16:46 CET 2013
Revision: 4374
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4374
Author: bartekskorupa
Date: 2013-03-14 17:16:45 +0000 (Thu, 14 Mar 2013)
Log Message:
-----------
change of several operators.
<Add Switches to outputs> changed to <Add Reroutes to Outputs> - shortcut changed to SLASH
New option added - ability to add reroutes to all or only to loose outputs.
Added SWAP REROUTES AND SWITCHES to replace ones by the others
Changed COPY LABEL - new options added - from active, from linked node, from linked socket
Added CLEAR LABEL
Some code cleanup: made use of new attributes like node.width, output.links and input.links
Modified Paths:
--------------
contrib/py/scripts/addons/node_efficiency_tools.py
Modified: contrib/py/scripts/addons/node_efficiency_tools.py
===================================================================
--- contrib/py/scripts/addons/node_efficiency_tools.py 2013-03-14 05:31:04 UTC (rev 4373)
+++ contrib/py/scripts/addons/node_efficiency_tools.py 2013-03-14 17:16:45 UTC (rev 4374)
@@ -19,8 +19,8 @@
bl_info = {
'name': "Nodes Efficiency Tools",
'author': "Bartek Skorupa",
- 'version': (2, 0.06),
- 'blender': (2, 6, 5),
+ 'version': (2, 0.07),
+ 'blender': (2, 6, 6),
'location': "Node Editor Properties Panel (Ctrl-SPACE)",
'description': "Nodes Efficiency Tools",
'warning': "",
@@ -38,7 +38,7 @@
# with attributes determinig if pass is used,
# and MultiLayer EXR outputs names and corresponding render engines
#
-# rl_outputs entry = [render_pass, rl_output_name, exr_output_name, in_internal, in_cycles]
+# rl_outputs entry = (render_pass, rl_output_name, exr_output_name, in_internal, in_cycles)
rl_outputs = (
('use_pass_ambient_occlusion', 'AO', 'AO', True, True),
('use_pass_color', 'Color', 'Color',True, False),
@@ -91,14 +91,11 @@
global links
space = context.space_data
- space_tree = space.node_tree
- tree = space_tree
+ tree = space.node_tree
nodes = tree.nodes
links = tree.links
active = nodes.active
- selected = [node for node in nodes if node.select]
context_active = context.active_node
- context_selected = context.selected_nodes
# check if we are working on regular node tree or node group is currently edited.
# if group is edited - active node of space_tree is the group
# if context.active_node != space active node - it means that the group is being edited.
@@ -160,50 +157,49 @@
for the_list in [selected_mix, selected_shader, selected_math]:
- if len(the_list) > 1:
+ if the_list:
count_before = len(nodes)
# sort list by loc_x - reversed
the_list.sort(key = lambda k: k[1], reverse = True)
# get maximum loc_x
- loc_x = the_list[0][1] + 300.0
+ loc_x = the_list[0][1] + 350.0
the_list.sort(key = lambda k: k[2], reverse = True)
loc_y = the_list[len(the_list) - 1][2]
offset_y = 40.0
if the_list == selected_shader:
offset_y = 150.0
- add_nodes = []
- for i in range(len(the_list)-1):
+ the_range = len(the_list)-1
+ do_hide = True
+ if len(the_list) == 1:
+ the_range = 1
+ do_hide = False
+ for i in range(the_range):
if the_list == selected_mix:
add = nodes.new('MIX_RGB')
add.blend_type = mode
add.show_preview = False
- add.hide = True
+ add.hide = do_hide
first = 1
second = 2
- if hasattr(add, 'width_hidden'):
- add.width_hidden = 100.0
+ add.width_hidden = 100.0
elif the_list == selected_math:
add = nodes.new('MATH')
add.operation = mode
- add.hide = True
+ add.hide = do_hide
first = 0
second = 1
- if hasattr(add, 'width_hidden'):
- add.width_hidden = 100.0
+ add.width_hidden = 100.0
elif the_list == selected_shader:
if mode == 'MIX':
add = nodes.new('MIX_SHADER')
first = 1
second = 2
- if hasattr(add, 'width_hidden'):
- add.width_hidden = 100.0
+ add.width_hidden = 100.0
elif mode == 'ADD':
add = nodes.new('ADD_SHADER')
first = 0
second = 1
- if hasattr(add, 'width_hidden'):
- add.width_hidden = 100.0
-
+ add.width_hidden = 100.0
add.location.x = loc_x
add.location.y = loc_y
loc_y += offset_y
@@ -217,13 +213,14 @@
for i in range(count_adds):
if i < count_adds - 1:
links.new(nodes[index-1].inputs[first], nodes[index].outputs[0])
- links.new(nodes[index].inputs[second], nodes[the_list[i+1][0]].outputs[0])
+ if len(the_list) > 1:
+ links.new(nodes[index].inputs[second], nodes[the_list[i+1][0]].outputs[0])
index -= 1
# set "last" of added nodes as active
nodes.active = nodes[count_before]
for [i, x, y] in the_list:
nodes[i].select = False
-
+
return {'FINISHED'}
@@ -342,101 +339,59 @@
def execute(self, context):
set_convenience_variables(context)
- n_index = len(nodes) # get index of new node when added
+ selected = [n for n in nodes if n.select]
+ reselect = [] # duplicated nodes will be selected after execution
active = nodes.active
- selected_i = [] # entry = node index
- selected_same_type_i = [] # entry = node index
- reconnects = [] #entry = [old index, new index]
- old_links = []
- new_links = []
+ if active.select:
+ reselect.append(active)
- for si, node in enumerate(nodes):
- if node.select:
- selected_i.append(si) # will be used to restore selection
- if active.type == node.type and node != active:
- selected_same_type_i.append(si)
-
- for si in selected_same_type_i:
- bpy.ops.node.select_all(action = 'DESELECT')
- nodes.active = active
- active.select = True
- bpy.ops.node.duplicate()
- copied = nodes.active
- copied.hide = nodes[si].hide
- copied.show_preview = nodes[si].show_preview
- copied.mute = nodes[si].mute
- copied.label = nodes[si].label
- copied.use_custom_color = nodes[si].use_custom_color
- copied.color = nodes[si].color
- if copied.parent:
- bpy.ops.node.parent_clear()
- locx = nodes[si].location.x
- locy = nodes[si].location.y
- # get absolute nodes[si] location
- parent = nodes[si].parent
- while parent:
- locx += parent.location.x
- locy += parent.location.y
- parent = parent.parent
- copied.location = [locx, locy]
- reconnects.append([si, n_index])
- n_index += 1
-
- for li, link in enumerate(links):
- from_node = None
- from_socket = None
- to_node = None
- to_socket = None
- for ni in selected_same_type_i:
- if link.from_node == nodes[ni]:
- from_node = ni
- for oi, output in enumerate(nodes[ni].outputs):
- if link.from_socket == output:
- from_socket = oi
- break
- for nj in range (len(nodes)):
- if link.to_node == nodes[nj]:
- to_node = nj
- for ii, input in enumerate(nodes[nj].inputs):
- if link.to_socket == input:
- to_socket = ii
- entry = [from_node, from_socket, to_node, to_socket]
- if entry not in old_links:
- old_links.append(entry)
- elif link.to_node == nodes[ni]:
- to_node = ni
- for ii, input in enumerate(nodes[ni].inputs):
- if link.to_socket == input:
- to_socket = ii
- break
- for nj in range (len(nodes)):
- if link.from_node == nodes[nj]:
- from_node = nj
- for oi, output in enumerate(nodes[nj].outputs):
- if link.from_socket == output:
- from_socket = oi
- entry = [from_node, from_socket, to_node, to_socket]
- if entry not in old_links:
- old_links.append(entry)
-
- for i, [fn, fs, tn, ts] in enumerate(old_links):
- for [old_i, new_i] in reconnects:
- if fn == old_i:
- fn = new_i
- if tn == old_i:
- tn = new_i
- new_links.append([fn, fs, tn, ts])
-
- for [fn, fs, tn, ts] in new_links:
- links.new(nodes[fn].outputs[fs], nodes[tn].inputs[ts])
-
+ for node in selected:
+ if node.type == active.type and node != active:
+ # duplicate active, relink links as in 'node', append copy to 'reselect', delete node
+ bpy.ops.node.select_all(action = 'DESELECT')
+ nodes.active = active
+ active.select = True
+ bpy.ops.node.duplicate()
+ copied = nodes.active
+ # Copied active should however inherit some properties from 'node'
+ attributes = (
+ 'hide', 'show_preview', 'mute', 'label',
+ 'use_custom_color', 'color', 'width', 'width_hidden',
+ )
+ for attr in attributes:
+ setattr(copied, attr, getattr(node, attr))
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list