W_smartAlign v1.1
This location is for Registered Users Only.
Perhaps you need to login or register.
10.0, 9.0, 8.0, 7.1, 7.0 or later
Linux, Mac, Windows
W_smartAlign
A script I wrote to make aligning your nodes faster in an easy and controllable way.
The way it works:
- If only one node is selected, the node will align to the nearest connected node (both inputs and outputs) in the desired direction
- Multiple nodes will align to the selected node that’s the furthest away in the desired direction
- If a node already shares the same position on one axis with a node it’s aligning to, the node will be placed next to other node instead of overlapping it.
- Takes a node’s screensize in account to ensure a correct alignment no matter what kind of node you’re dealing with.
- Ignores Viewers and child nodes with hidden inputs
New in v1.1:
- Undo now supported
Sample menu.py code
Note that Nukepedia is for some reason replacing double quotes with singles quotes. If you copy the following text, make sure to replace the single quotes around left/right/up/down with double quotes or the script will not work. Alternatively, you find the same code at the bottom of the W_smartAlign.py python file and copy it from there.
Nuke 9 and newer:
1 2 3 4 5 6 7 |
import W_smartAlign menuBar = nuke.menu('Nuke') |
Nuke 8 and older:
1 2 3 4 5 6 7 |
import W_smartAlign menuBar = nuke.menu('Nuke') |
Note that with this setup the ‘version up/down’ shortcuts will be overwritten. You are of course free to modify the menu.py code to change the shortcuts if that doesn't work for you. I personally however only use those function occasionally whereas I use this alignment tool all the time. Therefore I’d suggest assigning new shortcuts to the ‘version up/down’ functions instead, but that’s up to you of course. Personally I’m using the 'greater-than' and 'less-than'-signs (or ‘shift +.’ and ‘shift +,’ ) to version up and down:
1 2 3 4 5 |
#make sure to remove “, shortcutContext=2” when using Nuke 8 or older |
Comments
However I would suggest using a different default keyboard shortcut as these overwrite default nuke functions. (Especially alt+up/down for version up/down is extremely useful)
Thanks for the input, glad you like it!
I’m indeed aware of the the ‘version up/down’ shortcuts being overwritten. You are of course free to modify my code to change the shortcuts to something that works better for you.
I personally however only use those function occasionally whereas I use this alignment tool all the time. Therefore I’d suggest assigning new shortcuts to the ‘version up/down’ functions, but that’s up to you.
I included some extra code at the bottom of the mainpost.
Thanks for the feedback
Cheers
"...menu.py : error interpreting this plugin"
Under details it says:
"SynataxError: invalid syntax" with an " ^ " under "Context"
any ideas? Thanks!
If I'm correct, you're using Nuke 8 or older, right? Make sure to get rid of the all the 'shortcutContex t=2' in your menu.py, as this functionality is only supported in version 9.
I posted a version suitable for older versions of nuke in the mainpost, so make sure you copy the right one.
"Nuke" vs 'Nuke'
It doesn't allow any Undo though. Is that smth that could be implemented?
I tried to implement this when I initially wrote the tool, but couldn't figure out why it wasn't working. I gave it another try after I read your comment and found a workaround.
I just uploaded v1.1.
For whom it may interest: Turns out that for some reason changing a node's position by changing the values of the position knobs can not be undone. But using the 'setXpos' and 'setYpos' methods instead will do the trick.
menuBar = nuke.menu("Nuke")
menuBar.addCommand("Edit/Node/Align/Left", 'W_smartAlign.a lignNodes("left ")', "Alt+left", shortcutContext =2)
menuBar.addCommand("Edit/Node/Align/Right", 'W_smartAlign.a lignNodes("righ t")', "Alt+right", shortcutContext =2)
menuBar.addCommand("Edit/Node/Align/Up", 'W_smartAlign.a lignNodes("up") ', "Alt+up", shortcutContext =2)
menuBar.addCommand("Edit/Node/Align/Down", 'W_smartAlign.a lignNodes("down ")', "Alt+down", shortcutContext =2)
Added this:
import W_smartAlign
menuBar = nuke.menu("Nuke")
menuBar.addCommand("Edit/Node/Align/Left", 'W_smartAlign.a lignNodes("left ")', "Alt+left", shortcutContext =2)
menuBar.addCommand("Edit/Node/Align/Right", 'W_smartAlign.a lignNodes("righ t")', "Alt+right", shortcutContext =2)
menuBar.addCommand("Edit/Node/Align/Up", 'W_smartAlign.a lignNodes("up") ', "Alt+up", shortcutContext =2)
menuBar.addCommand("Edit/Node/Align/Down", 'W_smartAlign.a lignNodes("down ")', "Alt+down", shortcutContext =2)
in menu.py
and got this error message:
invalid syntax (, line 1)
Did I install correctly?
W_smartAlign.a lignNodes
See whether removing it fixes your problem. Cheers.
Nukepedia added the space between 'a' and 'lign'.
I had included the three apostrophes that were in your W_smartalign.py"
#--------------------------------------
#EXAMPLE MENU.PY CODE
#--------------------------------------
'''
import W_smartAlign
When I removed the ''', the script worked.
Thank you for this excellent timesaver.
full script
menuBar = nuke.menu('Nuke')
menuBar.addCommand('Edit/Node/Align/Left', 'W_smartAlign.a lignNodes("left ")', 'Alt+left', shortcutContext =2)
menuBar.addCommand('Edit/Node/Align/Right', 'W_smartAlign.a lignNodes("righ t")', 'Alt+right', shortcutContext =2)
menuBar.addCommand('Edit/Node/Align/Up', 'W_smartAlign.a lignNodes("up") ', 'Alt+up', shortcutContext =2)
menuBar.addCommand('Edit/Node/Align/Down', 'W_smartAlign.a lignNodes("down ")', 'Alt+down', shortcutContext =2)
and yet...It's a very helpful script. Thanks for your good support.
-Kito
可以不让他们重叠吗?
I am chinese, my english is so bad.
可以不让他们重叠吗?
(google translate: If two parallel nodes are not connected, they will overlap in parallel directions.
Can you not let them overlap? )
如何不重叠?
(google translate :If two vertical nodes are connected, one of them is not connected to another horizontal node, then alt+< or alt+>, the horizontal nodes will overlap.
How to not overlap?)
如何不重叠?
(google translate :If two vertical nodes are connected, one of them is not connected to another horizontal node, and then the three nodes are selected, then alt+< or alt+>, the horizontal nodes will overlap.
How to not overlap?)
I install the script on ( Nuke12.1v3) but still getting this error
any suggestion:
File "", line 1
W_smartAlign.a lignNodes("left ")
^
SyntaxError: invalid syntax
import W_smartAlign
menuBar = nuke.menu('Nuke')
menuBar.addCommand('Edit/Node/Align/Left', 'W_smartAlign.a lignNodes("left ")', 'Alt+left', shortcutContext =2)
menuBar.addCommand('Edit/Node/Align/Right', 'W_smartAlign.a lignNodes("righ t")', 'Alt+right', shortcutContext =2)
menuBar.addCommand('Edit/Node/Align/Up', 'W_smartAlign.a lignNodes("up") ', 'Alt+up', shortcutContext =2)
menuBar.addCommand('Edit/Node/Align/Down', 'W_smartAlign.a lignNodes("down ")', 'Alt+down', shortcutContext =2)
amazing tool! Thanks man. Just a little speed improvement I found, cause it's lagging sometimes in bigger scripts.
Line 65:
inputNodes = curNode.depende ncies(nuke.INPU TS)
outputNodes = curNode.depende nt(nuke.INPUTS, forceEvaluate = False)
Cheers
I don't know if this might be useful, but for those who are using this tool for Nuke 15, you might need to correct the syntax in the menu.py like this:
menuBar = nuke.menu('Nuke')
menuBar.addCommand("Edit/Node/Align/Left", 'W_smartAlign.a lignNodes("left ")', "Alt+left")
menuBar.addCommand('Edit/Node/Align/Right', 'W_smartAlign.a lignNodes("righ t")', "Alt+right")
menuBar.addCommand("Edit/Node/Align/Up", 'W_smartAlign.a lignNodes("up") ', "Alt+up")
menuBar.addCommand("Edit/Node/Align/Down", 'W_smartAlign.a lignNodes("down ")', "Alt+down")
RSS feed for comments to this post