Skip to content

Instantly share code, notes, and snippets.

@shrimo
Last active May 19, 2020 12:52
Show Gist options
  • Save shrimo/ceb12d84c2862b8fb2725b3e17d718ee to your computer and use it in GitHub Desktop.
Save shrimo/ceb12d84c2862b8fb2725b3e17d718ee to your computer and use it in GitHub Desktop.
Rendering version change
# Copy version_change.py file to /home/user/.nuke folder.
import version_change
menubar=nuke.menu("Nuke")
m=menubar.addMenu("&Pipeline")
m.addCommand("&Version change", "version_change.main()")
set cut_paste_input [stack 0]
version 12.0 v4
push $cut_paste_input
NoOp {
name NoOp1
tile_color 0xff5f00ff
label "Version control"
note_font_size 32
selected true
xpos 532
ypos -1137
addUserKnob {20 version_set l "Version control"}
addUserKnob {22 version_setup l Version T "import os\nimport nuke\n\n\ndef find_version(render, root):\n file = os.path.splitext(root.split('/')\[-1])\n shot = file\[0].split('-')\[0]\n elements = render.split('/')\n index = 0\n for element in elements:\n if shot == element:\n return elements\[index+1]\n index += 1\n return False\n\n\ndef main():\n read_nodes = nuke.selectedNodes()\n root = nuke.root().knob('name').value()\n current = None\n if read_nodes:\n for read_node in read_nodes:\n if read_node.Class() == \"Read\":\n current = find_version(read_node\['file'].getValue(), root)\n if current:\n break\n nuke.message('Current version: '+current)\n new_line = nuke.getInput('New version', current)\n if current and new_line:\n for node in read_nodes:\n if node.Class() == \"Read\":\n new_version = node\['file'].getValue().replace(current, new_line)\n if os.path.isdir(os.path.dirname(new_version)):\n node\['file'].setValue(new_version)\n else:\n nuke.message('Missing directory: '+os.path.dirname(new_version))\n return\n else:\n nuke.message('Select Read nodes')\n\n\nmain()" +STARTLINE}
}
# Copy version_change.py file to /home/user/.nuke folder.
import os
import nuke
def find_version(render, root):
file = os.path.splitext(root.split('/')[-1])
shot = file[0].split('-')[0]
elements = render.split('/')
index = 0
for element in elements:
if shot == element:
return elements[index+1]
index += 1
return False
def version_main():
read_nodes = nuke.selectedNodes()
root = nuke.root().knob('name').value()
current = None
if read_nodes:
for read_node in read_nodes:
if read_node.Class() == "Read":
current = find_version(read_node['file'].getValue(), root)
if current:
break
nuke.message('Current version: '+current)
new_line = nuke.getInput('New version', current)
if current and new_line:
for node in read_nodes:
if node.Class() == "Read":
new_version = node['file'].getValue().replace(current, new_line)
if os.path.isdir(os.path.dirname(new_version)):
node['file'].setValue(new_version)
else:
nuke.message('Missing directory: '+os.path.dirname(new_version))
return
else:
nuke.message('Select Read nodes')
menubar=nuke.menu("Nuke")
m=menubar.addMenu("&Pipeline")
m.addCommand("&Version change", "version_main()")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment