Skip to content

Commit

Permalink
Fixed bug when exporting USD
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesvink committed Oct 13, 2021
1 parent 768a463 commit 3ae08b3
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions hooks/tk-multi-publish2/basic/publish_session_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import maya.cmds as cmds
import maya.mel as mel
import sgtk
import time
import tempfile
import shutil

from tank_vendor import six

Expand Down Expand Up @@ -287,13 +288,11 @@ def publish(self, settings, item):
# This is a quick fix to make sure directories exists before executing the usd export command
publish_path = publish_path.replace("\\", "/")
publish_dir = os.path.dirname(publish_path)
publish_name = os.path.basename(publish_path)

# ensure the publish folder exists:
self.parent.ensure_folder_exists(publish_dir)

# Sleep quick fix for Windows/Maya because otherwise explorer thinks the directory is not existing
time.sleep(2)

start_frame, end_frame = _find_scene_animation_range()

# This is the really long Maya command to export everything in the scene to USDA
Expand All @@ -310,14 +309,26 @@ def publish(self, settings, item):
'Export" -pr -ea '
)

file_path = ' "' + publish_path + '"'
# Create temporary directory
with tempfile.TemporaryDirectory() as temp_directory:
# Setting file name
temp_file_path = os.path.join(temp_directory, publish_name).replace(
os.sep, "/"
)
file_path = ' "' + temp_file_path + '"'

# Setting final command
usd_command = usd_command + file_path + ";"

usd_command = usd_command + file_path + ";"
# Executing export command
self.parent.log_debug("Executing command: %s" % usd_command)
mel.eval(usd_command)

self.parent.log_debug("Executing command: %s" % usd_command)
mel.eval(usd_command)
# Copy directory
shutil.copy2(temp_file_path, publish_dir)
self.parent.log_debug("Copied file to publish path")

# Now that the path has been generated, hand it off to the
# Now that the usd file has been generated and copied, hand it off to the
super(MayaSessionUSDPublishPlugin, self).publish(settings, item)


Expand Down

0 comments on commit 3ae08b3

Please sign in to comment.