Created
August 5, 2016 20:12
-
-
Save danbradham/f57c7b2eef6658e4979cbf2c8736ccd6 to your computer and use it in GitHub Desktop.
Nuke python copy and paste at the specified position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For more modern Nuke users: QtGui has been replaced by QtWidgets. You can change line 2 to
from PySide2 import QtWidgets as QtGui