No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

createFolders.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import re, os, math
  2. import nuke, nukescripts
  3. class CreateFolders(KellerNukePlugin):
  4. def configurePlugin(self):
  5. menubar = nuke.menu("Nuke")
  6. m = menubar.addMenu("&Render")
  7. m.addCommand("CreateFolders",'createFolders.createFolders()', "F16")
  8. pass
  9. ##########################
  10. def createFolders():
  11. writeNodes = get_broken_write_nodes()
  12. if writeNodes:
  13. fix_broken_write_nodes()
  14. def get_broken_write_nodes():
  15. """
  16. Returns list of all write nodes that refer to non-existing paths (or an empty list).
  17. If nodes are selected only they will be checked.
  18. """
  19. nodes = nuke.selectedNodes()
  20. if not nodes: nodes = nuke.allNodes()
  21. n = [i for i in nodes if i.Class() == "Write"]
  22. result = []
  23. for curNode in n:
  24. fileKnob = curNode['file']
  25. try:
  26. if not os.path.exists(os.path.dirname(fileKnob.evaluate())):
  27. result.append(curNode)
  28. except:
  29. pass
  30. return result
  31. def fix_broken_write_nodes():
  32. """
  33. Create paths for all (selected) write nodes in case they don't exist yet.
  34. """
  35. nodes = get_broken_write_nodes()
  36. for curNode in nodes:
  37. thePath = os.path.dirname(curNode['file'].evaluate())
  38. if thePath and not os.path.exists(thePath):
  39. try:
  40. os.makedirs(thePath)
  41. print ("created directory "+thePath)
  42. except:
  43. nuke.message("CreateFolders.fix_broken_write_nodes(): Error creating "+thePath)