diff options
author | Greg Zaal <gregzzmail@gmail.com> | 2015-06-24 17:50:24 +0300 |
---|---|---|
committer | Greg Zaal <gregzzmail@gmail.com> | 2015-06-24 17:50:24 +0300 |
commit | ff3f5574174a6c411015974c4697c4bb2c84e0ef (patch) | |
tree | 03cfc2b3cc5051adf3b16a54e029d1a1471a167d /node_wrangler.py | |
parent | d2aa512ae8b1b326f41616a4109e7dadb36bd9d5 (diff) |
Node Wrangler: When doing auto-arrange, keep active node still.
Other selected nodes are arranged around the active one - I've been using this for a while and found this behavior is much more useful.
Diffstat (limited to 'node_wrangler.py')
-rw-r--r-- | node_wrangler.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/node_wrangler.py b/node_wrangler.py index 54e11fae..d7a0a2d0 100644 --- a/node_wrangler.py +++ b/node_wrangler.py @@ -19,8 +19,8 @@ bl_info = { "name": "Node Wrangler", "author": "Bartek Skorupa, Greg Zaal, Sebastian Koenig", - "version": (3, 27), - "blender": (2, 74, 0), + "version": (3, 28), + "blender": (2, 75, 0), "location": "Node Editor Toolbar or Ctrl-Space", "description": "Various tools to enhance and speed up node-based workflow", "warning": "", @@ -35,8 +35,9 @@ from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty, St from bpy_extras.io_utils import ImportHelper from mathutils import Vector from math import cos, sin, pi, hypot -from os import listdir, path +from os import path from glob import glob +from copy import copy ################# # rl_outputs: @@ -2674,7 +2675,6 @@ class NWAlignNodes(Operator, NWBase): margin = IntProperty(name='Margin', default=50, description='The amount of space between nodes') def execute(self, context): - # TODO prop: lock active (arrange everything without moving active node) nodes, links = get_nodes_links(context) margin = self.margin @@ -2684,8 +2684,11 @@ class NWAlignNodes(Operator, NWBase): selection.append(node) # If no nodes are selected, align all nodes + active_loc = None if not selection: selection = nodes + elif nodes.active in selection: + active_loc = copy(nodes.active.location) # make a copy, not a reference # Check if nodes should be layed out horizontally or vertically x_locs = [n.location.x + (n.dimensions.x / 2) for n in selection] # use dimension to get center of node, not corner @@ -2717,14 +2720,19 @@ class NWAlignNodes(Operator, NWBase): current_pos -= (current_margin * 0.3) + node.dimensions.y # use half-margin for vertical alignment node.location.x = mid_x - (node.dimensions.x / 2) - # Position nodes centered around where they used to be - locs = ([n.location.x + (n.dimensions.x / 2) for n in selection]) if horizontal else ([n.location.y - (n.dimensions.y / 2) for n in selection]) - new_mid = (max(locs) + min(locs)) / 2 - for node in selection: - if horizontal: - node.location.x += (mid_x - new_mid) - else: - node.location.y += (mid_y - new_mid) + # If active node is selected, center nodes around it + if active_loc is not None: + active_loc_diff = active_loc - nodes.active.location + for node in selection: + node.location += active_loc_diff + else: # Position nodes centered around where they used to be + locs = ([n.location.x + (n.dimensions.x / 2) for n in selection]) if horizontal else ([n.location.y - (n.dimensions.y / 2) for n in selection]) + new_mid = (max(locs) + min(locs)) / 2 + for node in selection: + if horizontal: + node.location.x += (mid_x - new_mid) + else: + node.location.y += (mid_y - new_mid) return {'FINISHED'} |