Skip to content

Instantly share code, notes, and snippets.

@danbradham
Created August 5, 2016 20:12
Show Gist options
  • Save danbradham/f57c7b2eef6658e4979cbf2c8736ccd6 to your computer and use it in GitHub Desktop.
Save danbradham/f57c7b2eef6658e4979cbf2c8736ccd6 to your computer and use it in GitHub Desktop.
Nuke python copy and paste at the specified position
import os
from PySide import QtGui
import nuke
import nukescripts
def copy_script():
nuke.nodeCopy('%clipboard%')
clipboard = QtGui.QApplication.clipboard()
script = clipboard.text()
return script
def paste_script(script, x, y, clear_selection=True):
if clear_selection:
nukescripts.clear_selection_recursive()
clipboard = QtGui.QApplication.clipboard()
clipboard.setText(script)
nuke.nodePaste('%clipboard%')
x1, y1 = 0, 0
for line in script.split('\n'):
if not x1 and 'xpos' in line:
x1 = int(line.split()[-1])
if not y1 and 'ypos' in line:
y1 = int(line.split()[-1])
n = nuke.selectedNodes()[-1]
x2, y2 = n.xpos(), n.ypos()
dx, dy = x2 - x1, y2 - y1
for n in nuke.selectedNodes():
nx = n.xpos() - dx
ny = n.ypos() - dy
n.setXYpos(nx + x, ny + y)
@StraightfaceStudios
Copy link

For more modern Nuke users: QtGui has been replaced by QtWidgets. You can change line 2 to

from PySide2 import QtWidgets as QtGui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment