11import pyblish .api
22import os
33import sys
4+ import platform
45import tempfile
56
7+
68from pymxs import runtime as rt
79from ayon_core .lib import run_subprocess
810from ayon_max .api .lib_rendersettings import RenderSettings
@@ -41,7 +43,8 @@ def process(self, instance):
4143 for camera in cameras :
4244 new_output = RenderSettings ().get_batch_render_output (camera ) # noqa
4345 new_output = new_output .replace ("\\ " , "/" )
44- new_filename = f"{ filename } _{ camera } { ext } "
46+ camera_name = camera .replace (":" , "_" )
47+ new_filename = f"{ filename } _{ camera_name } { ext } "
4548 new_filepath = os .path .join (new_folder , new_filename )
4649 new_filepath = new_filepath .replace ("\\ " , "/" )
4750 camera_scene_files .append (new_filepath )
@@ -55,17 +58,22 @@ def process(self, instance):
5558new_filepath = "{new_filepath}"
5659new_output = "{new_output}"
5760camera = "{camera}"
61+ camera_name = camera.replace(":", "_")
62+ target_camera_node = rt.getNodeByName(camera)
63+ rt.viewport.setCamera(target_camera_node)
5864rt.rendOutputFilename = new_output
5965directory = os.path.dirname(rt.rendOutputFilename)
6066directory = os.path.join(directory, filename)
67+ if not os.path.exists(directory):
68+ os.mkdir(directory)
6169render_elem = rt.maxOps.GetCurRenderElementMgr()
6270render_elem_num = render_elem.NumRenderElements()
6371if render_elem_num > 0:
6472 ext = "{ext}"
6573 for i in range(render_elem_num):
6674 renderlayer_name = render_elem.GetRenderElement(i)
6775 target, renderpass = str(renderlayer_name).split(":")
68- aov_name = f"{{directory}}_{camera }_{{renderpass}}..{ext}"
76+ aov_name = f"{{directory}}_{{camera_name} }_{{renderpass}}..{ext}"
6977 render_elem.SetRenderElementFileName(i, aov_name)
7078rt.saveMaxFile(new_filepath)
7179 """ ).format (filename = instance .name ,
@@ -74,11 +82,10 @@ def process(self, instance):
7482 camera = camera ,
7583 ext = fmt )
7684 scripts .append (script )
77-
7885 maxbatch_exe = os .path .join (
7986 os .path .dirname (sys .executable ), "3dsmaxbatch" )
8087 maxbatch_exe = maxbatch_exe .replace ("\\ " , "/" )
81- if sys . platform == "windows" :
88+ if platform . system (). lower () == "windows" :
8289 maxbatch_exe += ".exe"
8390 maxbatch_exe = os .path .normpath (maxbatch_exe )
8491 with tempfile .TemporaryDirectory () as tmp_dir_name :
@@ -90,16 +97,18 @@ def process(self, instance):
9097 for script in scripts :
9198 tmp .write (script + "\n " )
9299
93- try :
94- current_filepath = current_filepath . replace ( " \\ " , "/ " )
95- tmp_script_path = tmp_script_path .replace ("\\ " , "/" )
96- run_subprocess ([ maxbatch_exe , tmp_script_path ,
97- "-sceneFile" , current_filepath ])
98- except RuntimeError :
99- self . log . debug ( "Checking the scene files existing" )
100+ full_script = " \n " . join ( scripts )
101+ self . log . debug ( f"Failed running script { tmp_script_path } : \n { full_script } " )
102+ current_filepath = current_filepath .replace ("\\ " , "/" )
103+ tmp_script_path = tmp_script_path . replace ( " \\ " , "/" )
104+ run_subprocess ([ maxbatch_exe , tmp_script_path ,
105+ "-sceneFile" , current_filepath ],
106+ logger = self . log )
100107
101108 for camera_scene in camera_scene_files :
102109 if not os .path .exists (camera_scene ):
110+ full_script = "\n " .join (scripts )
111+ self .log .debug (f"Failed running script { tmp_script_path } :\n { full_script } " )
103112 self .log .error ("Camera scene files not existed yet!" )
104113 raise RuntimeError ("MaxBatch.exe doesn't run as expected" )
105114 self .log .debug (f"Found Camera scene:{ camera_scene } " )
0 commit comments