Sin descripción
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.

set_prerenderdirectory.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ## set_prerenderdirectory.py
  2. ##
  3. ## version 1.0 (2010-07-08): initial version based on set_renderdirectory
  4. ##
  5. import re, os, math
  6. import nuke, nukescripts
  7. default_format = "exr"
  8. scripts_folder = "Comp"
  9. render_folder = "450_PreComp"
  10. debug_flag = True
  11. ##########################
  12. def setPrerenderdirectory():
  13. """
  14. change output filename of write node to proper render location
  15. """
  16. try:
  17. the_node = nuke.selectedNode()
  18. if the_node.Class() != "Write":
  19. nuke.message("Please select a write node.")
  20. return
  21. except:
  22. nuke.message("Please select a write node.")
  23. return
  24. # comp saved?
  25. if not nuke.knob("root.name"):
  26. if nuke.ask("Script needs a file name first.\nSave and continue?"):
  27. try:
  28. nuke.scriptSave()
  29. except RuntimeError:
  30. # if save dialog was cancelled
  31. return
  32. else:
  33. return
  34. # test if script name is valid
  35. script_name = nuke.knob("root.name")
  36. script_path = os.path.dirname(script_name)
  37. script_name = os.path.splitext(os.path.basename(script_name))[0]
  38. new_path, num = re.subn("(?i)/"+scripts_folder+"/","/"+render_folder+"/",script_path,1)
  39. if num == 0:
  40. nuke.message("Script is not saved in "+scripts_folder+".\nRender directory can't be determined.")
  41. return
  42. # todo: make sure there are no extra directories beyond sequence and scene number (no "050_scripts/010/010_010/blabla")
  43. # ask for pretender description
  44. label = "pre"
  45. panel = nuke.Panel("Set pre-render directory")
  46. panel.addSingleLineInput("Label:", label)
  47. panel.addButton("Cancel")
  48. panel.addButton("OK")
  49. if panel.show() == 0:
  50. return
  51. # clean label for use in filenames
  52. label = panel.value("Label:")
  53. label = re.sub("[^\w-]","",label)
  54. new_path = new_path + "/" + script_name + "_" + label
  55. the_node.knob("file").setValue(new_path + "/" + script_name + "_" + label + ".####." + default_format)
  56. print "set pre-render directory of "+the_node.name()
  57. print
  58. # create directory?
  59. if not debug_flag:
  60. if not os.path.exists(new_path):
  61. try:
  62. os.makedirs(new_path)
  63. print "created directory "+new_path
  64. print
  65. except:
  66. nuke.message("Error creating "+new_path)
  67. # fin