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_renderdirectory.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ## set_renderdirectory.py
  2. ##
  3. ## version 1.2 (2012-12-28): update for new file structure
  4. ## version 1.1 (2010-06-07): removed unused functions
  5. ## version 1.0 (2010-05-11): initial version
  6. ##
  7. ## todo: ask for pretender, select different format than dpx?
  8. import re, os, math
  9. import nuke, nukescripts
  10. default_format = "dpx"
  11. scripts_folder = "Comp"
  12. render_folder = "500_Renders"
  13. debug_flag = False
  14. ##########################
  15. def setRenderdirectory():
  16. """
  17. change output filename of write node to proper render location
  18. """
  19. try:
  20. the_node = nuke.selectedNode()
  21. if the_node.Class() != "Write":
  22. nuke.message("Please select a write node.")
  23. return
  24. except:
  25. nuke.message("Please select a write node.")
  26. return
  27. # comp saved?
  28. if not nuke.knob("root.name"):
  29. if nuke.ask("Script needs a file name first.\nSave and continue?"):
  30. try:
  31. nuke.scriptSave()
  32. except RuntimeError:
  33. # if save dialog was cancelled
  34. return
  35. else:
  36. return
  37. # test if script name is valid
  38. script_name = nuke.knob("root.name")
  39. script_path = os.path.dirname(script_name)
  40. script_name = os.path.splitext(os.path.basename(script_name))[0]
  41. nuke.message("DEBUG: script_name" +script_name)
  42. new_path, num = re.subn("(?i)/"+scripts_folder+"/","/"+render_folder+"/",script_path,1)
  43. if num == 0:
  44. nuke.message("Script is not saved in "+scripts_folder+".\nRender directory can't be determined.")
  45. return
  46. # todo: make sure there are no extra directories beyond sequence and scene number (no "050_scripts/010/010_010/blabla")
  47. new_path = new_path + "/" + script_name
  48. the_node.knob("file").setValue(new_path + "/" + script_name + ".####." + default_format)
  49. print "updated directory of "+the_node.name()
  50. print
  51. # create directory?
  52. if not debug_flag:
  53. if not os.path.exists(new_path):
  54. try:
  55. os.makedirs(new_path)
  56. print "created directory "+new_path
  57. print
  58. except:
  59. nuke.message("Error creating "+new_path)
  60. # fin