PDA

View Full Version : simple scripting


ftaswin
03-05-2010, 12:22 AM
Hi,

I need to convert lots of exr squences to tiff16.

- How can I change multiple attributes on similar nodes at once?
- How can I link the file path on the read nodes to write nodes but replacing exr with tif?

This way I can copy and paste 1 node and swap the read node and i'm all set to go.

I'm curious of how to do


Ft it in scripting as well. I can do it easily with mel but Nuke is a whole new ball game for me. Thanks

thatoneguy
03-05-2010, 07:15 PM
Courtesty of Alkali22

for node in nuke.selectedNodes():
node["##KNOBNAME##"].setValue(##VALUE##)

for node in nuke.selectedNodes():
node["##KNOBNAME##"].setExpression("##EXPRESSION##")

ftaswin
03-06-2010, 11:48 AM
Thank youuuu

That's very handy...

One more major one for me:
What's the syntax to:
-Get the input node's file attribute
-And then replace exr to tif at the same time

Thank you all

ft

ChristopherP
03-06-2010, 08:15 PM
maybe it's not not exactly what you needed from your original question, but at least it should get you started :) . it might also not be the prettiest code ever since i also just started looking more into nuke scripting... also commented all of it for clarity.
if anyone knows a quicker way or finds errors, let me know ;)

#import a python module so we can do the search&replace stuff
import re

#select all nodes in the root graph
nuke.selectAll()

#loop through all selected read nodes to
for n in nuke.selectedNodes('Read'):

#get the full file and proxy paths
tmpDir = n.knob('file').value()
tmpProxyDir = n.knob('proxy').value()

# print the result for confirmation
print tmpDir
print tmpProxyDir

# replace .exr with .tif in the file and proxy paths
replFile = re.sub('.exr', '.tif', tmpDir)
replProxy = re.sub('.exr', '.tif', tmpProxyDir)

# set the new file and proxy paths
n.knob('file').setValue(replFile)
n.knob('proxy').setValue(replProxy)

ftaswin
03-07-2010, 09:33 AM
Thanks Chris,

That was the best explanation I got so far.

But the node I want to replace from exr to tif is write node, not the read node itself. And the write node should be able to capture it's parent's file attribute.

Any takers? Thanks

ftaswin
03-07-2010, 12:46 PM
Done.

Thanks Chris...
Oh, and unless anyone has a better suggestion? Feel free to improve, Cheers,

Ft




#import a python module so we can do the search&replace stuff
import re

#select all nodes in the root graph
nuke.selectAll()

#loop through all selected read nodes to
for n in nuke.selectedNodes('Read'):

#get the full file and proxy paths
tmpDir = n.knob('file').value()
tmpProxyDir = n.knob('proxy').value()

# print the result for confirmation
print tmpDir
print tmpProxyDir

# replace .exr with .tif in the file and proxy paths
replFile = re.sub('.tif', '.jpg', tmpDir)
replProxy = re.sub('.tif', '.jpg', tmpProxyDir)

r = nuke.createNode('Write')
r.setInput(0,n)
r.knob('file').setValue(replFile)
r["file_type"].setValue("tiff")
r["datatype"].setValue("16_bit")
r["channels"].setValue("rgba")
r["colorspace"].setValue("linear")
r["compression"].setValue("none")

ChristopherP
03-07-2010, 01:31 PM
that's something like what i had in mind...but hey, today's lazy sunday ;)

jorx
03-10-2010, 08:57 PM
Slight simplification; rather then manipulating the selection, you could try nuke.allNodes. A string argument will define the node type to return. For example:

nuke.allNodes('Read') # Result: [<Read1 at 0x0000000004E89470>]


nuke.allNodes('Write')
# Result: [<Write1 at 0x0000000004E89370>]

ftaswin
03-11-2010, 12:01 AM
That's what I had earlier. As time goes by sometimes I just want to change the selected ones. Cheers,

Ft

CGTalk Moderation
03-11-2010, 12:01 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.