Merge pull request #1136 from pypeclub/bugfix/maya_copy_mel

Maya copy mel
This commit is contained in:
Milan Kolar 2021-03-17 09:55:42 +01:00 committed by GitHub
commit 7dd9dbd1b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 0 deletions

View file

@ -12,6 +12,7 @@ from avalon.tools import workfiles
from pyblish import api as pyblish
from pype.lib import any_outdated
import pype.hosts.maya
from pype.hosts.maya.lib import copy_workspace_mel
from . import menu, lib
log = logging.getLogger("pype.hosts.maya")
@ -46,6 +47,7 @@ def install():
avalon.on("new", on_new)
avalon.before("save", on_before_save)
avalon.on("taskChanged", on_task_changed)
avalon.on("before.workfile.save", before_workfile_save)
log.info("Setting default family states for loader..")
avalon.data["familiesStateToggled"] = ["imagesequence"]
@ -203,3 +205,11 @@ def on_task_changed(*args):
"Context was changed",
("Context was changed to {}".format(avalon.Session["AVALON_ASSET"])),
)
def before_workfile_save(workfile_path):
if not workfile_path:
return
workdir = os.path.dirname(workfile_path)
copy_workspace_mel(workdir)

View file

@ -0,0 +1,18 @@
from pype.lib import PreLaunchHook
from pype.hosts.maya.lib import copy_workspace_mel
class PreCopyMel(PreLaunchHook):
"""Copy workspace.mel to workdir.
Hook `GlobalHostDataHook` must be executed before this hook.
"""
app_groups = ["maya"]
def execute(self):
workdir = self.launch_context.env.get("AVALON_WORKDIR")
if not workdir:
self.log.warning("BUG: Workdir is not filled.")
return
copy_workspace_mel(workdir)

26
pype/hosts/maya/lib.py Normal file
View file

@ -0,0 +1,26 @@
import os
import shutil
def copy_workspace_mel(workdir):
# Check that source mel exists
current_dir = os.path.dirname(os.path.abspath(__file__))
src_filepath = os.path.join(current_dir, "resources", "workspace.mel")
if not os.path.exists(src_filepath):
print("Source mel file does not exist. {}".format(src_filepath))
return
# Skip if workspace.mel already exists
dst_filepath = os.path.join(workdir, "workspace.mel")
if os.path.exists(dst_filepath):
return
# Create workdir if does not exists yet
if not os.path.exists(workdir):
os.makedirs(workdir)
# Copy file
print("Copying workspace mel \"{}\" -> \"{}\"".format(
src_filepath, dst_filepath
))
shutil.copy(src_filepath, dst_filepath)

View file

@ -695,11 +695,15 @@ class FilesWidget(QtWidgets.QWidget):
file_path = os.path.join(self.root, work_file)
pipeline.emit("before.workfile.save", file_path)
self._enter_session() # Make sure we are in the right session
self.host.save_file(file_path)
self.set_asset_task(self._asset, self._task)
pipeline.emit("after.workfile.save", file_path)
self.workfile_created.emit(file_path)
self.refresh()