Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# Name this file ml_AutoWrite_v1_0.py
import nuke, os
#open directory
def gdOpenDir():
selection = nuke.selectedNodes()
readnodes = []
for s in selection:
s = nuke.selectedNode()
path = os.path.dirname(s.knob('file').value())
print path
path = path.replace('/','\\')
path = path.replace('&','^&')
os.system('explorer %s' % path)
print path
#make directory
def gdMakeDir():
selection = nuke.selectedNodes()
readnodes = []
for i in selection:
if i.Class() == "Read":
print i.dependencies()
readnodes.append(i)
origpath = i.knob("file").value()
folder = os.path.dirname(i.knob("file").value())
osdir = nuke.callbacks.filenameFilter( folder )
print osdir
if not os.path.isdir(folder):
os.makedirs( osdir )
#open directory
selection = nuke.selectedNodes()
readnodes = []
for s in selection:
s = nuke.selectedNode()
path = os.path.dirname(s.knob('file').value())
print path
path = path.replace('/','\\')
path = path.replace('&','^&')
os.system('explorer %s' % path)
print path
#make write nodes
def gdMakeEXRWriteNodes():
selection = nuke.selectedNodes()
readnodes = []
for i in selection:
if i.Class() == "Read":
print i.dependencies()
readnodes.append(i)
for i in readnodes:
xpos = i['xpos'].value()
ypos = i['ypos'].value()
origpath = i.knob("file").value()
folder = os.path.dirname(i.knob("file").value())
path = folder+"/"+i.name()+'_####.exr'
startframe = i.knob("origfirst").value()
endframe = i.knob("origlast").value()
dependants = i.dependent()
filename = os.path.basename(i.knob("file").value())
rmvext = filename.split(".")[0]
rmvfct = rmvext.split("%")[0]
newfilename = rmvfct + "_bbox_"+ "%04d" + ".exr"
newdir = os.path.dirname(folder + "/" + "bbox" + "/")
osdir = nuke.callbacks.filenameFilter( newdir )
print osdir
if not os.path.isdir(newdir):
os.makedirs( osdir )
writenode = nuke.nodes.Write( file = folder + "/" + "bbox" + "/" + newfilename, name = i.name()+"_autoWrite", first = startframe, last = endframe)
writenode.setInput(0,i)
writenode.knob("channels").setValue("rgba")
#writenode.knob("raw").setValue(True)
writenode.knob("file_type").setValue("exr")
writenode.knob("autocrop").setValue(True)
writenode.knob("datatype").setValue("16 bit half")
writenode.knob("compression").setValue("Zip (16 scanlines")
#set selected read nodes input and output frames
# Needs to check for node type
def setInAndOutFrames():
n = nuke.Root()
nff = str(n.firstFrame())
nlf = str(n.lastFrame())
selection = nuke.selectedNodes()
readnodes = []
inframe = nuke.getInput('Choose In Frame', nff)
outframe = nuke.getInput('Choose Out Frame', nlf)
newinframe = int(inframe)
newoutframe = int(outframe)
for i in selection:
if i.Class() == "Read":
print i.dependencies()
readnodes.append(i)
i.knob("first").setValue(newinframe)
i.knob("origfirst").setValue(newinframe)
i.knob("last").setValue(newoutframe)
i.knob("origlast").setValue(newoutframe)
# Create Read Node from Selected Read or Write nodes and set in and out frames to match comp
def copyFilePathToNewRead():
selection = nuke.selectedNodes()
readnodes = []
n = nuke.Root()
for i in selection:
origpath = i.knob("file").value()
folder = os.path.dirname(i.knob("file").value())
print origpath
readnode = nuke.nodes.Read( file = origpath )
#readnode.setInput(0,i)
readnode.knob("first").setValue(n.firstFrame())
readnode.knob("origfirst").setValue(n.firstFrame())
readnode.knob("last").setValue(n.lastFrame())
readnode.knob("origlast").setValue(n.lastFrame())
xPos = i.xpos()
yPos = i.ypos()
val = 80
movedown = (yPos + val)
readnode.setXYpos ( xPos, movedown )
print readnode['xpos'].value()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment