11
11
import subprocess
12
12
import sys
13
13
import shutil
14
+ import datetime
14
15
15
16
HookBaseClass = sgtk .get_hook_baseclass ()
16
17
@@ -337,23 +338,29 @@ def publish(self, settings, item):
337
338
338
339
# =======================
339
340
# 1. Export the Maya scene to FBX
340
- # The FBX will be exported to the current work folder, but any other
341
- # destination folder could be specified instead
341
+ # The FBX will be exported to a temp folder
342
+ # Another folder can be specified as long as the name has no spaces
343
+ # Spaces are not allowed in command line Unreal Python args
344
+ self .parent .ensure_folder_exists (self .temp_folder )
345
+ fbx_folder = self .temp_folder
346
+
347
+ # Get the filename from the work file
342
348
work_path = item .properties .get ("work_path" )
343
349
work_path = os .path .normpath (work_path )
344
-
345
- # Split the destination path into folder and filename
346
- fbx_folder = os .path .split (work_path )[0 ]
347
350
work_name = os .path .split (work_path )[1 ]
348
- work_name = os .path .splitext (work_name )[0 ]
351
+ work_name = os .path .splitext (work_name )[0 ]
349
352
350
353
# Replace non-word characters in filename, Unreal doesn't like those
351
354
# Substitute '_' instead
352
355
exp = re .compile (u"\W" , re .UNICODE )
353
356
work_name = exp .sub ("_" , work_name )
354
357
358
+ # Use current time as string as a unique identifier
359
+ now = datetime .datetime .now ()
360
+ timestamp = str (now .hour ) + str (now .minute ) + str (now .second )
361
+
355
362
# Replace file extension with .fbx and suffix it with "_turntable"
356
- fbx_name = work_name + "_turntable.fbx"
363
+ fbx_name = work_name + "_" + timestamp + " _turntable.fbx"
357
364
fbx_output_path = os .path .join (fbx_folder , fbx_name )
358
365
359
366
# Export the FBX to the given output path
@@ -374,11 +381,8 @@ def publish(self, settings, item):
374
381
script_path = os .path .abspath (script_path )
375
382
376
383
# Workaround for script path with spaces in it
377
- do_temp_folder_cleanup = False
378
384
if " " in script_path :
379
385
# Make temporary copies of the scripts to a path without spaces
380
- self .parent .ensure_folder_exists (self .temp_folder )
381
-
382
386
script_destination = self .temp_folder + "unreal_setup_turntable.py"
383
387
shutil .copy (script_path , script_destination )
384
388
script_path = script_destination
@@ -405,9 +409,6 @@ def publish(self, settings, item):
405
409
script_args .append (turntable_map_path )
406
410
407
411
self ._unreal_execute_script (unreal_exec_path , unreal_project_path , script_path , script_args )
408
-
409
- if do_temp_folder_cleanup :
410
- shutil .rmtree (self .temp_folder )
411
412
412
413
# =======================
413
414
# 4. Render the turntable to movie.
@@ -502,13 +503,16 @@ def finalize(self, settings, item):
502
503
# bump the session file to the next version
503
504
# self._save_to_next_version(item.properties["maya_path"], item, _save_session)
504
505
505
- # Delete the exported FBX
506
- fbx_path = item .properties .get ("temp_fbx_path" )
507
- if fbx_path :
508
- try :
509
- os .remove (fbx_path )
510
- except :
511
- pass
506
+ # Delete the exported FBX and scripts from the temp folder
507
+ shutil .rmtree (self .temp_folder )
508
+
509
+ # Revive this when Unreal supports spaces in command line Python args
510
+ # fbx_path = item.properties.get("temp_fbx_path")
511
+ # if fbx_path:
512
+ # try:
513
+ # os.remove(fbx_path)
514
+ # except:
515
+ # pass
512
516
513
517
def _get_version_entity (self , item ):
514
518
"""
0 commit comments