mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 05:42:15 +01:00
Merge pull request #199 from BigRoy/master
Fix published textures sometimes not being remapped correctly (LKD-17)
This commit is contained in:
commit
4315c4de98
1 changed files with 51 additions and 12 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import os
|
||||
import json
|
||||
import tempfile
|
||||
import contextlib
|
||||
from collections import OrderedDict
|
||||
|
||||
from maya import cmds
|
||||
|
|
@ -11,6 +13,38 @@ import colorbleed.api
|
|||
import colorbleed.maya.lib as lib
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def no_workspace_dir():
|
||||
"""Force maya to a fake temporary workspace directory.
|
||||
|
||||
Note: This is not maya.cmds.workspace 'rootDirectory' but the 'directory'
|
||||
|
||||
This helps to avoid Maya automatically remapping image paths to files
|
||||
relative to the currently set directory.
|
||||
|
||||
"""
|
||||
|
||||
# Store current workspace
|
||||
original = cmds.workspace(query=True, directory=True)
|
||||
|
||||
# Set a fake workspace
|
||||
fake_workspace_dir = tempfile.mkdtemp()
|
||||
cmds.workspace(directory=fake_workspace_dir)
|
||||
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
try:
|
||||
cmds.workspace(directory=original)
|
||||
except RuntimeError:
|
||||
# If the original workspace directory didn't exist either
|
||||
# ignore the fact that it fails to reset it to the old path
|
||||
pass
|
||||
|
||||
# Remove the temporary directory
|
||||
os.rmdir(fake_workspace_dir)
|
||||
|
||||
|
||||
class ExtractLook(colorbleed.api.Extractor):
|
||||
"""Extract Look (Maya Ascii + JSON)
|
||||
|
||||
|
|
@ -65,18 +99,23 @@ class ExtractLook(colorbleed.api.Extractor):
|
|||
with lib.renderlayer(layer):
|
||||
# TODO: Ensure membership edits don't become renderlayer overrides
|
||||
with lib.empty_sets(sets, force=True):
|
||||
with lib.attribute_values(remap):
|
||||
with avalon.maya.maintained_selection():
|
||||
cmds.select(sets, noExpand=True)
|
||||
cmds.file(maya_path,
|
||||
force=True,
|
||||
typ="mayaAscii",
|
||||
exportSelected=True,
|
||||
preserveReferences=False,
|
||||
channels=True,
|
||||
constraints=True,
|
||||
expressions=True,
|
||||
constructionHistory=True)
|
||||
# To avoid Maya trying to automatically remap the file
|
||||
# textures relative to the `workspace -directory` we force
|
||||
# it to a fake temporary workspace. This fixes textures
|
||||
# getting incorrectly remapped. (LKD-17, PLN-101)
|
||||
with no_workspace_dir():
|
||||
with lib.attribute_values(remap):
|
||||
with avalon.maya.maintained_selection():
|
||||
cmds.select(sets, noExpand=True)
|
||||
cmds.file(maya_path,
|
||||
force=True,
|
||||
typ="mayaAscii",
|
||||
exportSelected=True,
|
||||
preserveReferences=False,
|
||||
channels=True,
|
||||
constraints=True,
|
||||
expressions=True,
|
||||
constructionHistory=True)
|
||||
|
||||
# Write the JSON data
|
||||
self.log.info("Extract json..")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue