mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
implement validator for model name in 3dsmax
This commit is contained in:
parent
06c0bf3feb
commit
45bb933e80
6 changed files with 183 additions and 1 deletions
39
openpype/hosts/max/api/action.py
Normal file
39
openpype/hosts/max/api/action.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from pymxs import runtime as rt
|
||||
|
||||
import pyblish.api
|
||||
|
||||
from openpype.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]
|
||||
self.log.info(
|
||||
"Selecting invalid objects: %s", ", ".join(invalid_names)
|
||||
)
|
||||
|
||||
rt.Select(invalid)
|
||||
93
openpype/hosts/max/plugins/publish/validate_model_name.py
Normal file
93
openpype/hosts/max/plugins/publish/validate_model_name.py
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Validate model nodes names."""
|
||||
import re
|
||||
|
||||
import pyblish.api
|
||||
from pymxs import runtime as rt
|
||||
|
||||
from openpype.hosts.max.api.action import SelectInvalidAction
|
||||
|
||||
from openpype.pipeline.publish import (
|
||||
OptionalPyblishPluginMixin,
|
||||
PublishValidationError,
|
||||
ValidateContentsOrder)
|
||||
|
||||
|
||||
class ValidateModelName(pyblish.api.InstancePlugin,
|
||||
OptionalPyblishPluginMixin):
|
||||
"""Validate name of model
|
||||
|
||||
starts with (somename)_###_(materialID)_GEO
|
||||
|
||||
"""
|
||||
optional = True
|
||||
order = ValidateContentsOrder
|
||||
hosts = ["max"]
|
||||
families = ["model"]
|
||||
label = "Validate Model Name"
|
||||
actions = [SelectInvalidAction]
|
||||
regex = ""
|
||||
|
||||
@classmethod
|
||||
def get_invalid(cls, instance):
|
||||
invalid = []
|
||||
#TODO: validation regex for validation
|
||||
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 Frame Range...")
|
||||
return
|
||||
|
||||
invalid = self.get_invalid(instance)
|
||||
|
||||
if invalid:
|
||||
raise PublishValidationError(
|
||||
"Model naming is invalid. See the log.")
|
||||
|
|
@ -56,6 +56,12 @@
|
|||
"enabled": false,
|
||||
"attributes": {}
|
||||
},
|
||||
"ValidateModelName": {
|
||||
"enabled": true,
|
||||
"optional": true,
|
||||
"active": false,
|
||||
"regex": "(?P<subset>.*)_(GEO)"
|
||||
},
|
||||
"ValidateLoadedPlugin": {
|
||||
"enabled": false,
|
||||
"optional": true,
|
||||
|
|
|
|||
|
|
@ -48,6 +48,30 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "dict",
|
||||
"collapsible": true,
|
||||
"key": "ValidateModelName",
|
||||
"label": "Validate Model Name",
|
||||
"checkbox_key": "enabled",
|
||||
"children": [
|
||||
{
|
||||
"type": "boolean",
|
||||
"key": "enabled",
|
||||
"label": "Enabled"
|
||||
},
|
||||
{
|
||||
"type": "boolean",
|
||||
"key": "optional",
|
||||
"label": "Optional"
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"key": "regex",
|
||||
"label": "validation regex"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "dict",
|
||||
"collapsible": true,
|
||||
|
|
|
|||
|
|
@ -38,6 +38,20 @@ class FamilyMappingItemModel(BaseSettingsModel):
|
|||
)
|
||||
|
||||
|
||||
class ValidateModelName(BaseSettingsModel):
|
||||
enabled: bool = Field(title="Enabled")
|
||||
optional: bool = Field(title="Optional")
|
||||
active: bool = Field(title="Active")
|
||||
regex: str = Field(
|
||||
"(?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):
|
||||
enabled: bool = Field(title="Enabled")
|
||||
optional: bool = Field(title="Optional")
|
||||
|
|
@ -101,6 +115,12 @@ DEFAULT_PUBLISH_SETTINGS = {
|
|||
"enabled": False,
|
||||
"attributes": "{}"
|
||||
},
|
||||
"ValidateModelName": {
|
||||
"enabled": True,
|
||||
"optional": True,
|
||||
"active": False,
|
||||
"regex": "(?P<subset>.*)_(GEO)"
|
||||
},
|
||||
"ValidateLoadedPlugin": {
|
||||
"enabled": False,
|
||||
"optional": True,
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
__version__ = "0.1.4"
|
||||
__version__ = "0.1.5"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue