Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Maya: Optimize validate plug-in path attributes #5522

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pyblish.api

from openpype.hosts.maya.api.lib import pairwise
from openpype.hosts.maya.api.action import SelectInvalidAction
from openpype.pipeline.publish import (
ValidateContentsOrder,
PublishValidationError
Expand All @@ -19,37 +21,50 @@ class ValidatePluginPathAttributes(pyblish.api.InstancePlugin):
hosts = ['maya']
families = ["workfile"]
label = "Plug-in Path Attributes"
actions = [SelectInvalidAction]

def get_invalid(self, instance):
# Attributes are defined in project settings
attribute = []

@classmethod
def get_invalid(cls, instance):
invalid = list()

# get the project setting
validate_path = (
iLLiCiTiT marked this conversation as resolved.
Show resolved Hide resolved
instance.context.data["project_settings"]["maya"]["publish"]
)
file_attr = validate_path["ValidatePluginPathAttributes"]["attribute"]
file_attr = cls.attribute
if not file_attr:
return invalid

# get the nodes and file attributes
for node, attr in file_attr.items():
# check the related nodes
targets = cmds.ls(type=node)
# Consider only valid node types to avoid "Unknown object type" warning
all_node_types = set(cmds.allNodeTypes())
node_types = [key for key in file_attr.keys() if key in all_node_types]

for target in targets:
# get the filepath
file_attr = "{}.{}".format(target, attr)
filepath = cmds.getAttr(file_attr)
for node, node_type in pairwise(cmds.ls(type=node_types,
tokejepsen marked this conversation as resolved.
Show resolved Hide resolved
showType=True)):
# get the filepath
file_attr = "{}.{}".format(node, file_attr[node_type])
filepath = cmds.getAttr(file_attr)

if filepath and not os.path.exists(filepath):
self.log.error("File {0} not exists".format(filepath)) # noqa
invalid.append(target)
if filepath and not os.path.exists(filepath):
cls.log.error("{} '{}' uses non-existing filepath: {}"
.format(node_type, node, filepath))
invalid.append(node)

return invalid

def process(self, instance):
"""Process all directories Set as Filenames in Non-Maya Nodes"""
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError("Non-existent Path "
"found: {0}".format(invalid))
raise PublishValidationError(
title="Plug-in Path Attributes",
message="Non-existent filepath found on nodes: {}".format(
", ".join(invalid)
),
description=(
"## Plug-in nodes use invalid filepaths\n"
"The workfile contains nodes from plug-ins that use "
"filepaths which do not exist.\n\n"
"Please make sure their filepaths are correct and the "
"files exist on disk."
)
)
Loading