top of page

ALIGN NODES

  • jnietomonco
  • Feb 9, 2023
  • 1 min read

With this code, you can align all the nodes you have selected. You can either align them in X or align them in Y. The hotkey I use is ctrl+l for horizontal alignment, and crtl+shift+l for vertical.


ree

I like my scripts to be as organized as I can have them, and this code makes it super easy to make sure the connections have straight lines.

Expand Align Nodes

import nuke
            
def alignY():
    selected = nuke.selectedNodes()
    yPosList = []
    heightList = []

    for i in selected:
        yPos = i['ypos'].getValue()
        yPosList.append(yPos)
        height = i.screenHeight()/2
        heightList.append(height)

    avrgYPos = sum(yPosList)/len(yPosList)
    print 'Average Position is %s' % avrgYPos
    lowestHeight = min(heightList)
    print 'Lowest Height is %s' % lowestHeight

    for i in selected:
        if i.screenHeight()/2 == lowestHeight:
            i['ypos'].setValue(avrgYPos)
        else:
            newHeight = i.screenHeight()/2 - lowestHeight
            i['ypos'].setValue(avrgYPos-newHeight)
            
def alignX():
    selected = nuke.selectedNodes()
    xPosList = []
    widthList = []
    
    for i in selected:
        xPos = i['xpos'].getValue()
        xPosList.append(xPos)
        width = i.screenWidth()/2
        widthList.append(width)
    
    avrgXPos = sum(xPosList)/len(xPosList)
    print 'Average Position is %s' % avrgXPos
    lowestWidth = min(widthList)
    print 'Lowest Width is %s' % lowestWidth
    
    for i in selected:
        if i.screenWidth()/2 == lowestWidth:
            i['xpos'].setValue(avrgXPos)
        else:
            newWidth = i.screenWidth()/2 - lowestWidth
            i['xpos'].setValue(avrgXPos-newWidth)

Javier Nieto Moncó © 2025

  • linkedin
  • vimeo
  • generic-social-link
bottom of page