mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
ported Validate Model Name from OP to ayon_core
This commit is contained in:
commit
19461e5512
4 changed files with 172 additions and 0 deletions
42
client/ayon_core/hosts/max/api/action.py
Normal file
42
client/ayon_core/hosts/max/api/action.py
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
from pymxs import runtime as rt
|
||||||
|
|
||||||
|
import pyblish.api
|
||||||
|
|
||||||
|
from ayon_core.pipeline.publish import get_errored_instances_from_context
|
||||||
|
|
||||||
|
|
||||||
|
class SelectInvalidAction(pyblish.api.Action):
|
||||||
|
"""Select invalid objects in Blender when a publish plug-in failed."""
|
||||||
|
label = "Select Invalid"
|
||||||
|
on = "failed"
|
||||||
|
icon = "search"
|
||||||
|
|
||||||
|
def process(self, context, plugin):
|
||||||
|
errored_instances = get_errored_instances_from_context(context,
|
||||||
|
plugin=plugin)
|
||||||
|
|
||||||
|
# Get the invalid nodes for the plug-ins
|
||||||
|
self.log.info("Finding invalid nodes...")
|
||||||
|
invalid = list()
|
||||||
|
for instance in errored_instances:
|
||||||
|
invalid_nodes = plugin.get_invalid(instance)
|
||||||
|
if invalid_nodes:
|
||||||
|
if isinstance(invalid_nodes, (list, tuple)):
|
||||||
|
invalid.extend(invalid_nodes)
|
||||||
|
else:
|
||||||
|
self.log.warning(
|
||||||
|
"Failed plug-in doesn't have any selectable objects."
|
||||||
|
)
|
||||||
|
|
||||||
|
if not invalid:
|
||||||
|
self.log.info("No invalid nodes found.")
|
||||||
|
return
|
||||||
|
invalid_names = [obj.name for obj in invalid if isinstance(obj, str)]
|
||||||
|
if not invalid_names:
|
||||||
|
invalid_names = [obj.name for obj, _ in invalid]
|
||||||
|
invalid = [obj for obj, _ in invalid]
|
||||||
|
self.log.info(
|
||||||
|
"Selecting invalid objects: %s", ", ".join(invalid_names)
|
||||||
|
)
|
||||||
|
|
||||||
|
rt.Select(invalid)
|
||||||
|
|
@ -0,0 +1,100 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Validate model nodes names."""
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pyblish.api
|
||||||
|
from pymxs import runtime as rt
|
||||||
|
|
||||||
|
from ayon_core.hosts.max.api.action import SelectInvalidAction
|
||||||
|
|
||||||
|
from ayon_core.pipeline.publish import (
|
||||||
|
OptionalPyblishPluginMixin,
|
||||||
|
PublishValidationError,
|
||||||
|
ValidateContentsOrder)
|
||||||
|
|
||||||
|
|
||||||
|
class ValidateModelName(pyblish.api.InstancePlugin,
|
||||||
|
OptionalPyblishPluginMixin):
|
||||||
|
"""Validate Model Name
|
||||||
|
Validation regex is (.*)_(?P<subset>.*)_(GEO) by default.
|
||||||
|
e.g. {SOME_RANDOM_NAME}_{YOUR_SUBSET_NAME}_GEO should be your
|
||||||
|
default model name
|
||||||
|
|
||||||
|
The regex of (?P<subset>.*) can be replaced by (?P<asset>.*)
|
||||||
|
and (?P<project>.*).
|
||||||
|
e.g.
|
||||||
|
- (.*)_(?P<asset>.*)_(GEO) check if your model name is
|
||||||
|
{SOME_RANDOM_NAME}_{CURRENT_ASSET_NAME}_GEO
|
||||||
|
- (.*)_(?P<project>.*)_(GEO) check if your model name is
|
||||||
|
{SOME_RANDOM_NAME}_{CURRENT_PROJECT_NAME}_GEO
|
||||||
|
|
||||||
|
"""
|
||||||
|
optional = True
|
||||||
|
order = ValidateContentsOrder
|
||||||
|
hosts = ["max"]
|
||||||
|
families = ["model"]
|
||||||
|
label = "Validate Model Name"
|
||||||
|
actions = [SelectInvalidAction]
|
||||||
|
regex = ""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_invalid(cls, instance):
|
||||||
|
invalid = []
|
||||||
|
model_names = [model.name for model in instance.data.get("members")]
|
||||||
|
cls.log.debug(model_names)
|
||||||
|
if not model_names:
|
||||||
|
cls.log.error("No Model found in the OP Data.")
|
||||||
|
invalid.append(model_names)
|
||||||
|
for name in model_names:
|
||||||
|
invalid_model_name = cls.get_invalid_model_name(instance, name)
|
||||||
|
invalid.extend(invalid_model_name)
|
||||||
|
|
||||||
|
return invalid
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_invalid_model_name(cls, instance, name):
|
||||||
|
invalid = []
|
||||||
|
regex = cls.regex
|
||||||
|
reg = re.compile(regex)
|
||||||
|
matched_name = reg.match(name)
|
||||||
|
project_name = instance.context.data["projectName"]
|
||||||
|
current_asset_name = instance.context.data["asset"]
|
||||||
|
if matched_name is None:
|
||||||
|
cls.log.error("invalid model name on: {}".format(name))
|
||||||
|
cls.log.error("name doesn't match regex {}".format(regex))
|
||||||
|
invalid.append((rt.getNodeByName(name),
|
||||||
|
"Model name doesn't match regex"))
|
||||||
|
else:
|
||||||
|
if "asset" in reg.groupindex:
|
||||||
|
if matched_name.group("asset") != current_asset_name:
|
||||||
|
cls.log.error(
|
||||||
|
"Invalid asset name of the model {}.".format(name)
|
||||||
|
)
|
||||||
|
invalid.append((rt.getNodeByName(name),
|
||||||
|
"Model with invalid asset name"))
|
||||||
|
if "subset" in reg.groupindex:
|
||||||
|
if matched_name.group("subset") != instance.name:
|
||||||
|
cls.log.error(
|
||||||
|
"Invalid subset name of the model {}.".format(name)
|
||||||
|
)
|
||||||
|
invalid.append((rt.getNodeByName(name),
|
||||||
|
"Model with invalid subset name"))
|
||||||
|
if "project" in reg.groupindex:
|
||||||
|
if matched_name.group("project") != project_name:
|
||||||
|
cls.log.error(
|
||||||
|
"Invalid project name of the model {}.".format(name)
|
||||||
|
)
|
||||||
|
invalid.append((rt.getNodeByName(name),
|
||||||
|
"Model with invalid project name"))
|
||||||
|
return invalid
|
||||||
|
|
||||||
|
def process(self, instance):
|
||||||
|
if not self.is_active(instance.data):
|
||||||
|
self.log.debug("Skipping Validate Model Name...")
|
||||||
|
return
|
||||||
|
|
||||||
|
invalid = self.get_invalid(instance)
|
||||||
|
|
||||||
|
if invalid:
|
||||||
|
raise PublishValidationError(
|
||||||
|
"Model naming is invalid. See the log.")
|
||||||
|
|
@ -56,6 +56,12 @@
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"attributes": {}
|
"attributes": {}
|
||||||
},
|
},
|
||||||
|
"ValidateModelName": {
|
||||||
|
"enabled": true,
|
||||||
|
"optional": true,
|
||||||
|
"active": false,
|
||||||
|
"regex": "(.*)_(?P<subset>.*)_(GEO)"
|
||||||
|
},
|
||||||
"ValidateLoadedPlugin": {
|
"ValidateLoadedPlugin": {
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,20 @@ class FamilyMappingItemModel(BaseSettingsModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ValidateModelNameModel(BaseSettingsModel):
|
||||||
|
enabled: bool = SettingsField(title="Enabled")
|
||||||
|
optional: bool = SettingsField(title="Optional")
|
||||||
|
active: bool = SettingsField(title="Active")
|
||||||
|
regex: str = SettingsField(
|
||||||
|
"(.*)_(?P<subset>.*)_(GEO)",
|
||||||
|
title="Validation regex",
|
||||||
|
description=(
|
||||||
|
"Regex for validating model name. You can use named "
|
||||||
|
" capturing groups:(?P<asset>.*) for Asset name"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ValidateLoadedPluginModel(BaseSettingsModel):
|
class ValidateLoadedPluginModel(BaseSettingsModel):
|
||||||
enabled: bool = SettingsField(title="Enabled")
|
enabled: bool = SettingsField(title="Enabled")
|
||||||
optional: bool = SettingsField(title="Optional")
|
optional: bool = SettingsField(title="Optional")
|
||||||
|
|
@ -68,6 +82,10 @@ class PublishersModel(BaseSettingsModel):
|
||||||
default_factory=ValidateLoadedPluginModel,
|
default_factory=ValidateLoadedPluginModel,
|
||||||
title="Validate Loaded Plugin"
|
title="Validate Loaded Plugin"
|
||||||
)
|
)
|
||||||
|
ValidateModelName: ValidateModelNameModel = SettingsField(
|
||||||
|
default_factory=ValidateModelNameModel,
|
||||||
|
title="Validate Model Name"
|
||||||
|
)
|
||||||
ExtractModelObj: BasicValidateModel = SettingsField(
|
ExtractModelObj: BasicValidateModel = SettingsField(
|
||||||
default_factory=BasicValidateModel,
|
default_factory=BasicValidateModel,
|
||||||
title="Extract OBJ",
|
title="Extract OBJ",
|
||||||
|
|
@ -101,6 +119,12 @@ DEFAULT_PUBLISH_SETTINGS = {
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
"attributes": "{}"
|
"attributes": "{}"
|
||||||
},
|
},
|
||||||
|
"ValidateModelName": {
|
||||||
|
"enabled": True,
|
||||||
|
"optional": True,
|
||||||
|
"active": False,
|
||||||
|
"regex": "(.*)_(?P<subset>.*)_(GEO)"
|
||||||
|
},
|
||||||
"ValidateLoadedPlugin": {
|
"ValidateLoadedPlugin": {
|
||||||
"enabled": False,
|
"enabled": False,
|
||||||
"optional": True,
|
"optional": True,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue