Sorry for the delay.
The only thing I see that I would definitely change is to avoid calling
nuke.message in your loop. That will get annoying in a hurry... If you really
want the feedback, maybe consider gathering a list of created directories and
displaying it at the end. Other than that, just a few minor tweaks.
def createWriteDirs():
import nuke, os, errno
created = []
skipped = []
for w in nuke.allNodes('Write'):
outFile = nuke.callbacks.filenameFilter(nuke.filename(w))
if not outFile:
skipped.append(w.name())
continue
dirName = os.path.dirname(outFile)
if w['disable'].value() or (not w.inputs()) or os.path.exists(dirName):
skipped.append(w.name())
continue
try:
os.makedirs(dirName)
except OSError, e:
if e.errno == errno.EEXIST:
skipped.append(w.name())
else:
raise
else:
created.append((w.name(), dirName))
result = []
if created:
result.append('Created %d output directories:\n' % len(created))
result.extend([' %s: %s' % x for x in created])
if skipped:
result.append('\nSkipped %d nodes:\n' % len(skipped))
result.append(', '.join(skipped))
if result:
nuke.message('\n'.join(result))
else:
nuke.message('No Write nodes found')
-Nathan
From: Richard Bobo
Sent: Wednesday, May 16, 2012 7:43 PM
To: Nuke user discussion
Subject: Re: [Nuke-users] Python Question - How to test for disabled node…?
Nathan,
FYI --
Here's what I came up with; yet another variation on a function to create Write
node output directories for all the write nodes in a script -- except for the
write nodes that are either a) disabled or b) without an input or c) without an
output pathname or d) have an existing directory path. Of course, I'll add it
as a menu selection… Please let me know if you see any glaring errors! Thanks
for your help.
def createWriteDirs():
import nuke, os, errno
for w in nuke.allNodes('Write'):
name=nuke.Node.name(w)
file=nuke.filename(w)
if w['disable'].value()==True:
print "%s is disabled, skipping..." %(name)
elif w.inputs()==0:
print "%s has no input, skipping..." %(name)
elif file==None:
print "%s has an empty output path, skipping..." %(name)
elif (os.path.isdir(os.path.dirname(file))):
print "%s path exists, skipping..." %(name)
else:
dir = os.path.dirname(file)
osdir = nuke.callbacks.filenameFilter(dir)
try:
os.makedirs(osdir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
finally:
print "%s - created output directory:\n %s" %(name,osdir)
nuke.message("%s - created output directory:\n %s" %(name,osdir))
createWriteDirs()
Rich
Rich Bobo
Senior VFX Compositor
Mobile: (248) 840-2665
Web: http://richbobo.com/
"A man should never be ashamed to own that he has been in the wrong, which is
but saying that he is wiser today than he was yesterday."
- Alexander Pope (1688-1744) English Poet
On May 16, 2012, at 9:13 PM, Richard Bobo wrote:
Perfect. Thanks, Nathan!
Rich
On May 16, 2012, at 9:10 PM, Nathan Rusch wrote:
node['disable'].value()
If it’s True, the node is disabled.
-Nathan
From: Richard Bobo
Sent: Wednesday, May 16, 2012 6:07 PM
To: Nuke-Users Mailing List
Subject: [Nuke-users] Python Question - How to test for disabled node…?
Hi,
Anyone know a good way to test a node to see if it is disabled? I want to
be able to ignore all disabled Write nodes in my script. I figured out how to
ignore unconnected nodes and nodes without any pathname, but I haven't stumbled
on the method for checking if the node is disabled, yet...
Thanks for any help,
Rich
Rich Bobo
Senior VFX Compositor
Mobile: (248) 840-2665
Web: http://richbobo.com/
"Failure is the opportunity to begin again more intelligently."
- Henry Ford
----------------------------------------------------------------------------
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users
--------------------------------------------------------------------------------
_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users_______________________________________________
Nuke-users mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-users