Created
March 1, 2016 11:04
-
-
Save madoodia/1ec33c8c7c12794c0242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# [email protected] | |
# -------------------- | |
import pyblish.api | |
from maya import cmds, mel | |
def _get_has_history(): | |
invalid = [] | |
for node in cmds.ls(type='mesh'): | |
if len(cmds.listHistory(node)) > 1: | |
invalid.append(node) | |
continue | |
return invalid | |
class ClearHistoryAction(pyblish.api.Action): | |
label = "Clear History" | |
on = "failed" | |
icon = "hand-o-up" | |
def process(self, instance): | |
"""Repair by deleting the history of meshes""" | |
invalid = _get_has_history() | |
for each in invalid: | |
cmds.select(each, r=True) | |
mel.eval("DeleteHistory;") | |
self.log.info("Success on deleting history of %s" % each) | |
class ValidateHistory(pyblish.api.InstancePlugin): | |
"""Your model have History or not..!?""" | |
order = pyblish.api.ValidatorOrder | |
families = ['anr.model'] | |
hosts = ['maya'] | |
optional = True | |
label = "Detect History" | |
version = (0, 0, 2) | |
actions = [ | |
pyblish.api.Category("Clear History"), | |
ClearHistoryAction | |
] | |
def process(self, instance): | |
invalid = _get_has_history() | |
if invalid: | |
raise RuntimeError( | |
"Meshes found in instance[{0}] with history: {1}".format(instance, invalid)) | |
# def repair(self, instance): | |
# """Repair by deleting the empty layers""" | |
# invalid = self._get_has_history() | |
# for each in invalid: | |
# cmds.select(each, r=True) | |
# mel.eval("DeleteHistory;") | |
# self.log.info("Success on deleting history of %s" % each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure you only check the objects in the instance. Here's some updated code: