Skip to content

Commit

Permalink
Merge pull request #116 from ynput/enhancement/OP-7085_ValidateNoAnim…
Browse files Browse the repository at this point in the history
…ation

Max: Validate No Animation
  • Loading branch information
moonyuet authored Mar 7, 2024
2 parents 7bf7780 + 7adf8b6 commit 1b7e22b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
import pyblish.api
from pymxs import runtime as rt
from ayon_core.pipeline import (
PublishValidationError,
OptionalPyblishPluginMixin
)
from ayon_core.hosts.max.api.action import SelectInvalidAction


def get_invalid_keys(obj):
"""function to check on whether there is keyframe in
Args:
obj (str): object needed to check if there is a keyframe
Returns:
bool: whether invalid object(s) exist
"""
for transform in ["Position", "Rotation", "Scale"]:
num_of_key = rt.NumKeys(rt.getPropertyController(
obj.controller, transform))
if num_of_key > 0:
return True
return False


class ValidateNoAnimation(pyblish.api.InstancePlugin,
OptionalPyblishPluginMixin):
"""Validates No Animation
Ensure no keyframes on nodes in the Instance
"""

order = pyblish.api.ValidatorOrder
families = ["model"]
hosts = ["max"]
optional = True
label = "Validate No Animation"
actions = [SelectInvalidAction]

def process(self, instance):
if not self.is_active(instance.data):
return
invalid = self.get_invalid(instance)
if invalid:
raise PublishValidationError(
"Keyframes found on:\n\n{0}".format(invalid)
,
title="Keyframes on model"
)

@staticmethod
def get_invalid(instance):
"""Get invalid object(s) which have keyframe(s)
Args:
instance (pyblish.api.instance): Instance
Returns:
list: list of invalid objects
"""
invalid = [invalid for invalid in instance.data["members"]
if invalid.isAnimated or get_invalid_keys(invalid)]

return invalid
9 changes: 9 additions & 0 deletions server_addon/max/server/settings/publishers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class PublishersModel(BaseSettingsModel):
"the system automatically skips checking it"
)
)
ValidateNoAnimation: BasicValidateModel = SettingsField(
default_factory=BasicValidateModel,
title="Validate No Animation"
)
ValidateLoadedPlugin: ValidateLoadedPluginModel = SettingsField(
default_factory=ValidateLoadedPluginModel,
title="Validate Loaded Plugin"
Expand Down Expand Up @@ -152,6 +156,11 @@ class PublishersModel(BaseSettingsModel):
"optional": True,
"active": False
},
"ValidateNoAnimation": {
"enabled": True,
"optional": True,
"active": False,
},
"ExtractModelObj": {
"enabled": True,
"optional": True,
Expand Down
2 changes: 1 addition & 1 deletion server_addon/max/server/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.6"
__version__ = "0.1.7"

0 comments on commit 1b7e22b

Please sign in to comment.