Skip to content

Instantly share code, notes, and snippets.

@dbr
dbr / find_plugins.py
Created September 11, 2020 06:07
Method to find external nodes
def _find_ext_nodes(extension, ignore_classes=None):
# type: (str, Optional[List[str]]) -> Dict[str, nuke.Node]
"""Find nodes which are not part of default Nuke
"""
if ignore_classes is None:
ignore_classes = []
by_class = {} # type: Dict[str, nuke.Node]
for n in nuke.allNodes(recurseGroups=True):
@dbr
dbr / mutable-defaults-args.diff
Created September 3, 2018 08:11
pytoshop patches
diff --git a/pytoshop/layers.py b/pytoshop/layers.py
index d4bef85..a6577c4 100755
--- a/pytoshop/layers.py
+++ b/pytoshop/layers.py
@@ -642,10 +642,14 @@ class LayerRecord(object):
visible=True, # type: bool
pixel_data_irrelevant=False, # type: bool
name='', # type: unicode
- channels={}, # type: Dict[int, ChannelImageData]
- blocks=[], # type: List[tagged_block.TaggedBlock]
@dbr
dbr / menu.py
Created September 5, 2017 04:02
Alternative viewer connection shorcuts - alt+1..9 connect viewer, 1..9 only switch viewer
def viewer_shotcuts_alt():
# Alt+1, Alt+2 etc to connect node to viewer
for n in range(9):
def connect_viewer(n=n):
selection = nuke.selectedNodes()
nuke.connectViewer(n, nuke.selectedNode())
[node.setSelected(False) for node in nuke.selectedNodes()]
[node.setSelected(True) for node in selection]
nuke.menu("Node Graph").addMenu("ViewerThing").addCommand(
@dbr
dbr / expression_evaluation_slowness.nk
Created March 7, 2016 08:23
Demonstration of Nuke, "Bug 35703. Expressions force tree to validate unnecessarily, when changing unrelated parts of the tree."
set cut_paste_input [stack 0]
version 8.0 v6
push $cut_paste_input
Keyer {
operation "luminance key"
range {0.09247749808 1 1 1}
name Keyer1
selected true
xpos -398
ypos -86
"""
RGB to XYZ gamut-remapping matrix calculation.
Main function is rgb_to_xyz_matrix.
"""
class MatrixError(Exception):
pass
class NonInvertableMatrix(MatrixError):
@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
@dbr
dbr / gist:f3b72e72eb0beb0426e6
Created August 22, 2014 10:32
strava_challenges_2014_08_22.txt
INFO:__main__:Found challenge 1, http://app.strava.com/challenges/1 (Rapha Festive 500)
INFO:__main__:Found challenge 2, http://app.strava.com/challenges/2 (Strava Ride Base Mile Blast)
INFO:__main__:Found challenge 3, http://app.strava.com/challenges/3 (Strava Run Base Mile Blast)
DEBUG:__main__:Challenge 4 does not exist
INFO:__main__:Found challenge 5, http://app.strava.com/challenges/5 (A Classic Challenge from Specialized)
DEBUG:__main__:Challenge 6 does not exist
DEBUG:__main__:Challenge 7 does not exist
DEBUG:__main__:Challenge 8 does not exist
DEBUG:__main__:Challenge 9 does not exist
INFO:__main__:Found challenge 10, http://app.strava.com/challenges/10 (GU 100,000 Mile Challenge)
@dbr
dbr / timewarpdropframe.nk
Created July 21, 2014 00:38
Nuke drop-frame TimeWarp calculator
set cut_paste_input [stack 0]
version 7.0 v5
push $cut_paste_input
UvLensDistort8 {
inputs 0
name UvLensDistort8_1
label "Shot: \[lindex \[split \[value file] \"/\"] 4]\nElem: \[lindex \[split \[value file] \"/\"] 6]\n(\[lindex \[split \[value file] \"/\"] 7] analysis \[lindex \[split \[value file] \"/\"] 9])"
selected true
xpos -166
ypos -26
@dbr
dbr / stages_data_0.csv
Created July 4, 2014 13:26
High-speed capture from Stages power meter
Timestamp kgf Nm
2014-06-26 19:21:25.025
46441 7.3 12.2
46473 7.5 12.6
46505 7.9 13.1
46537 -1.7 -2.8
46569 -2.2 -3.7
46601 -3.5 -5.8
46633 -4.0 -6.7
46665 -4.1 -6.8
function process(canvas, func) {
function setPixel(imageData, x, y, rgba) {
var index = (x + y * imageData.width) * 4;
for (var i = 0; i < 4; i++) {
imageData.data[index + i] = rgba[i] * 255;
}
}
var ctx = canvas.getContext("2d");