mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
Fix
Updating
This commit is contained in:
parent
cdc0a80846
commit
8c626920cc
1 changed files with 37 additions and 25 deletions
|
|
@ -32,7 +32,7 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
# Copy the xgen palette file from published version.
|
||||
_, maya_extension = os.path.splitext(maya_filepath)
|
||||
source = maya_filepath.replace(maya_extension, ".xgen")
|
||||
destination = os.path.join(
|
||||
xgen_file = os.path.join(
|
||||
project_path,
|
||||
"{basename}__{namespace}__{name}.xgen".format(
|
||||
basename=os.path.splitext(os.path.basename(current_file()))[0],
|
||||
|
|
@ -40,15 +40,15 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
name=name
|
||||
)
|
||||
).replace("\\", "/")
|
||||
self.log.info("Copying {} to {}".format(source, destination))
|
||||
shutil.copy(source, destination)
|
||||
self.log.info("Copying {} to {}".format(source, xgen_file))
|
||||
shutil.copy(source, xgen_file)
|
||||
|
||||
# Modify xgDataPath and xgProjectPath to have current workspace first
|
||||
# and published version directory second. This ensure that any newly
|
||||
# created xgen files are created in the current workspace.
|
||||
resources_path = os.path.join(os.path.dirname(source), "resources")
|
||||
lines = []
|
||||
with open(destination, "r") as f:
|
||||
with open(xgen_file, "r") as f:
|
||||
for line in [line.rstrip() for line in f]:
|
||||
if line.startswith("\txgDataPath"):
|
||||
data_path = line.split("\t")[-1]
|
||||
|
|
@ -67,10 +67,12 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
|
||||
lines.append(line)
|
||||
|
||||
with open(destination, "w") as f:
|
||||
with open(xgen_file, "w") as f:
|
||||
f.write("\n".join(lines))
|
||||
|
||||
return destination
|
||||
xgd_file = xgen_file.replace(".xgen", ".xgd")
|
||||
|
||||
return xgen_file, xgd_file
|
||||
|
||||
def process_reference(self, context, name, namespace, options):
|
||||
# Validate workfile has a path.
|
||||
|
|
@ -78,7 +80,8 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
QtWidgets.QMessageBox.warning(
|
||||
None,
|
||||
"",
|
||||
"Current workfile has not been saved."
|
||||
"Current workfile has not been saved. Please save the workfile"
|
||||
" before loading an Xgen."
|
||||
)
|
||||
return
|
||||
|
||||
|
|
@ -87,10 +90,9 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
)
|
||||
|
||||
name = context["representation"]["data"]["xgenName"]
|
||||
xgen_file = self.setup_xgen_palette_file(
|
||||
xgen_file, xgd_file = self.setup_xgen_palette_file(
|
||||
maya_filepath, namespace, name
|
||||
)
|
||||
xgd_file = xgen_file.replace(".xgen", ".xgd")
|
||||
|
||||
# Reference xgen. Xgen does not like being referenced in under a group.
|
||||
new_nodes = []
|
||||
|
|
@ -105,17 +107,7 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
)
|
||||
|
||||
xgen_palette = cmds.ls(nodes, type="xgmPalette", long=True)[0]
|
||||
cmds.setAttr(
|
||||
"{}.xgBaseFile".format(xgen_palette),
|
||||
os.path.basename(xgen_file),
|
||||
type="string"
|
||||
)
|
||||
cmds.setAttr(
|
||||
"{}.xgFileName".format(xgen_palette),
|
||||
os.path.basename(xgd_file),
|
||||
type="string"
|
||||
)
|
||||
cmds.setAttr("{}.xgExportAsDelta".format(xgen_palette), True)
|
||||
self.set_palette_attributes(xgen_palette, xgen_file, xgd_file)
|
||||
|
||||
# This create an expression attribute of float. If we did not add
|
||||
# any changes to collection, then Xgen does not create an xgd file
|
||||
|
|
@ -133,10 +125,24 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
|
||||
return new_nodes
|
||||
|
||||
def set_palette_attributes(self, xgen_palette, xgen_file, xgd_file):
|
||||
cmds.setAttr(
|
||||
"{}.xgBaseFile".format(xgen_palette),
|
||||
os.path.basename(xgen_file),
|
||||
type="string"
|
||||
)
|
||||
cmds.setAttr(
|
||||
"{}.xgFileName".format(xgen_palette),
|
||||
os.path.basename(xgd_file),
|
||||
type="string"
|
||||
)
|
||||
cmds.setAttr("{}.xgExportAsDelta".format(xgen_palette), True)
|
||||
|
||||
def update(self, container, representation):
|
||||
"""Workflow for updating Xgen.
|
||||
|
||||
- Copy and overwrite the workspace .xgen file.
|
||||
- Copy and potentially overwrite the workspace .xgen file.
|
||||
- Export changes to delta file.
|
||||
- Set collection attributes to not include delta files.
|
||||
- Update xgen maya file reference.
|
||||
- Apply the delta file changes.
|
||||
|
|
@ -144,22 +150,28 @@ class XgenLoader(openpype.hosts.maya.api.plugin.ReferenceLoader):
|
|||
|
||||
We have to do this workflow because when using referencing of the xgen
|
||||
collection, Maya implicitly imports the Xgen data from the xgen file so
|
||||
we dont have any control over added the delta file changes.
|
||||
we dont have any control over when adding the delta file changes.
|
||||
|
||||
There is an implicit increment of the xgen and delta files, due to
|
||||
using the workfile basename.
|
||||
"""
|
||||
|
||||
container_node = container["objectName"]
|
||||
members = get_container_members(container_node)
|
||||
xgen_palette = cmds.ls(members, type="xgmPalette", long=True)[0]
|
||||
reference_node = get_reference_node(members, self.log)
|
||||
namespace = cmds.referenceQuery(reference_node, namespace=True)[1:]
|
||||
|
||||
xgen_file = self.setup_xgen_palette_file(
|
||||
xgen_file, xgd_file = self.setup_xgen_palette_file(
|
||||
get_representation_path(representation),
|
||||
namespace,
|
||||
representation["data"]["xgenName"]
|
||||
)
|
||||
xgd_file = xgen_file.replace(".xgen", ".xgd")
|
||||
|
||||
xgen_palette = cmds.ls(members, type="xgmPalette", long=True)[0]
|
||||
# Export current changes to apply later.
|
||||
xgenm.createDelta(xgen_palette.replace("|", ""), xgd_file)
|
||||
|
||||
self.set_palette_attributes(xgen_palette, xgen_file, xgd_file)
|
||||
|
||||
attribute_data = {
|
||||
"{}.xgFileName".format(xgen_palette): os.path.basename(xgen_file),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue