Skip to content

Instantly share code, notes, and snippets.

@dbr
dbr / ociorv.mu
Created April 26, 2011 13:48
WIP OCIO integration for RV
use rvtypes;
use app_utils;
use commands;
use extra_commands;
use rvui;
require math;
require io;
require qt;
require system;
"""Broken-but-maybe-informative version of code from
http://stackoverflow.com/questions/13124235/python-process-communications-via-pipes-race-condition#13124235
"""
import os
import string
def safe_write(*args, **kwargs):
while True:
try:
from PySide import QtGui, QtCore
def findDagWidget():
stack = QtGui.QApplication.topLevelWidgets()
while stack:
widget = stack.pop()
if widget.windowTitle() == 'Node Graph':
# You should probably be a little safer with this return, but the actual DAG widget
# seems to be here consistently... if not, it should be the only child of 'widget'
@dbr
dbr / nuke_duplicate_node.py
Created April 17, 2013 00:38
Duplicate a Nuke node
import nuke
def duplicate_node(node, to_file = None):
"""Slightly convoluted but reliable(?) way duplicate a node, using
the same functionality as the regular copy and paste.
Could almost be done tidily by doing:
for knobname in src_node.knobs():
@dbr
dbr / nuke_viewer_shortcut_intercept.py
Created June 4, 2013 04:12
Test of finding Nuke's viewer widget, and intercepting the hardwired "c" shortcut and rewiring it to view the RGB channel
"""Test of finding Nuke's viewer widget, and intercepting the hardwired "c" shortcut and rewiring it to view the RGB channel
"""
from PySide import QtGui, QtCore
def findviewer():
stack = QtGui.QApplication.topLevelWidgets()
viewers = []
while stack:
@dbr
dbr / inverting_linearlight.nk
Created July 12, 2013 05:58
Inverting linear images
#! Nuke7.0 -nx
version 7.0 v8
Root {
inputs 0
name /tmp/inverting_linearlight.nk
format "2048 1556 0 0 2048 1556 1 2K_Super_35(full-ap)"
proxy_type scale
proxy_format "1024 778 0 0 1024 778 1 1K_Super_35(full-ap)"
}
BackdropNode {
@dbr
dbr / gist:8016555
Created December 18, 2013 02:51
Get all files referenced by a Nuke file knob
def _collect_file_knob(node):
# disallow locally-cached paths, otherwise evaluating gives localised path
if node.knob('cacheLocal'):
orig = node['cacheLocal'].value()
node['cacheLocal'].setValue('never')
# Frame range to evaluate
fr = nuke.FrameRange(node['first'].value(), node['last'].value(), 1)
# Evaluation context thing, modified later
@dbr
dbr / nuke_save_with_root_settings.py
Last active September 21, 2023 07:27
Saving selected Nuke nodes to file, preserving the root settings
def root_settings_to_string(root):
"""Serialise the project settings. Used when writing the selected
nodes (otherwise things like the frame range would be lost)
"""
# Write non-default settings, in .nk script format. Also write
# user-knob definitons to avoid errors like NUKE-256
rootstring = root.writeKnobs(nuke.TO_SCRIPT | nuke.WRITE_USER_KNOB_DEFS)
# TODO: Why doesn't writeKnobs write [first/last]_frame? Also
@fredrikaverpil
fredrikaverpil / custom_ui_docked.py
Last active December 1, 2022 16:29
Create custom PySide GUI and dock it into Nuke UI
import PySide.QtCore as QtCore
import PySide.QtGui as QtGui
from nukescripts import panels
class PanelTest(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.setLayout(QtGui.QVBoxLayout())
self.myTable = QtGui.QTableWidget()
self.myTable.header = ['Date', 'Files', 'Size', 'Path' ]
"""
RGB to XYZ gamut-remapping matrix calculation.
Main function is rgb_to_xyz_matrix.
"""
class MatrixError(Exception):
pass
class NonInvertableMatrix(MatrixError):