mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
ValidateInstanceInContext was split into 2 separated plugins with own settings in maya and nuke host
This commit is contained in:
parent
f58cacb716
commit
eeda206278
6 changed files with 157 additions and 40 deletions
|
|
@ -5,6 +5,8 @@ from __future__ import absolute_import
|
||||||
import pyblish.api
|
import pyblish.api
|
||||||
import openpype.api
|
import openpype.api
|
||||||
|
|
||||||
|
from maya import cmds
|
||||||
|
|
||||||
|
|
||||||
class SelectInvalidInstances(pyblish.api.Action):
|
class SelectInvalidInstances(pyblish.api.Action):
|
||||||
"""Select invalid instances in Outliner."""
|
"""Select invalid instances in Outliner."""
|
||||||
|
|
@ -18,13 +20,12 @@ class SelectInvalidInstances(pyblish.api.Action):
|
||||||
# Get the errored instances
|
# Get the errored instances
|
||||||
failed = []
|
failed = []
|
||||||
for result in context.data["results"]:
|
for result in context.data["results"]:
|
||||||
if result["error"] is None:
|
if (
|
||||||
continue
|
result["error"] is None
|
||||||
if result["instance"] is None:
|
or result["instance"] is None
|
||||||
continue
|
or result["instance"] in failed
|
||||||
if result["instance"] in failed:
|
or result["plugin"] != plugin
|
||||||
continue
|
):
|
||||||
if result["plugin"] != plugin:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
failed.append(result["instance"])
|
failed.append(result["instance"])
|
||||||
|
|
@ -44,25 +45,10 @@ class SelectInvalidInstances(pyblish.api.Action):
|
||||||
self.deselect()
|
self.deselect()
|
||||||
|
|
||||||
def select(self, instances):
|
def select(self, instances):
|
||||||
if "nuke" in pyblish.api.registered_hosts():
|
cmds.select(instances, replace=True, noExpand=True)
|
||||||
import avalon.nuke.lib
|
|
||||||
import nuke
|
|
||||||
avalon.nuke.lib.select_nodes(
|
|
||||||
[nuke.toNode(str(x)) for x in instances]
|
|
||||||
)
|
|
||||||
|
|
||||||
if "maya" in pyblish.api.registered_hosts():
|
|
||||||
from maya import cmds
|
|
||||||
cmds.select(instances, replace=True, noExpand=True)
|
|
||||||
|
|
||||||
def deselect(self):
|
def deselect(self):
|
||||||
if "nuke" in pyblish.api.registered_hosts():
|
cmds.select(deselect=True)
|
||||||
import avalon.nuke.lib
|
|
||||||
avalon.nuke.lib.reset_selection()
|
|
||||||
|
|
||||||
if "maya" in pyblish.api.registered_hosts():
|
|
||||||
from maya import cmds
|
|
||||||
cmds.select(deselect=True)
|
|
||||||
|
|
||||||
|
|
||||||
class RepairSelectInvalidInstances(pyblish.api.Action):
|
class RepairSelectInvalidInstances(pyblish.api.Action):
|
||||||
|
|
@ -92,23 +78,14 @@ class RepairSelectInvalidInstances(pyblish.api.Action):
|
||||||
|
|
||||||
context_asset = context.data["assetEntity"]["name"]
|
context_asset = context.data["assetEntity"]["name"]
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
if "nuke" in pyblish.api.registered_hosts():
|
self.set_attribute(instance, context_asset)
|
||||||
import openpype.hosts.nuke.api as nuke_api
|
|
||||||
origin_node = instance[0]
|
|
||||||
nuke_api.lib.recreate_instance(
|
|
||||||
origin_node, avalon_data={"asset": context_asset}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.set_attribute(instance, context_asset)
|
|
||||||
|
|
||||||
def set_attribute(self, instance, context_asset):
|
def set_attribute(self, instance, context_asset):
|
||||||
if "maya" in pyblish.api.registered_hosts():
|
cmds.setAttr(
|
||||||
from maya import cmds
|
instance.data.get("name") + ".asset",
|
||||||
cmds.setAttr(
|
context_asset,
|
||||||
instance.data.get("name") + ".asset",
|
type="string"
|
||||||
context_asset,
|
)
|
||||||
type="string"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ValidateInstanceInContext(pyblish.api.InstancePlugin):
|
class ValidateInstanceInContext(pyblish.api.InstancePlugin):
|
||||||
|
|
@ -124,7 +101,7 @@ class ValidateInstanceInContext(pyblish.api.InstancePlugin):
|
||||||
order = openpype.api.ValidateContentsOrder
|
order = openpype.api.ValidateContentsOrder
|
||||||
label = "Instance in same Context"
|
label = "Instance in same Context"
|
||||||
optional = True
|
optional = True
|
||||||
hosts = ["maya", "nuke"]
|
hosts = ["maya"]
|
||||||
actions = [SelectInvalidInstances, RepairSelectInvalidInstances]
|
actions = [SelectInvalidInstances, RepairSelectInvalidInstances]
|
||||||
|
|
||||||
def process(self, instance):
|
def process(self, instance):
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Validate if instance asset is the same as context asset."""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import nuke
|
||||||
|
|
||||||
|
import pyblish.api
|
||||||
|
import openpype.api
|
||||||
|
import avalon.nuke.lib
|
||||||
|
import openpype.hosts.nuke.api as nuke_api
|
||||||
|
|
||||||
|
|
||||||
|
class SelectInvalidInstances(pyblish.api.Action):
|
||||||
|
"""Select invalid instances in Outliner."""
|
||||||
|
|
||||||
|
label = "Select Instances"
|
||||||
|
icon = "briefcase"
|
||||||
|
on = "failed"
|
||||||
|
|
||||||
|
def process(self, context, plugin):
|
||||||
|
"""Process invalid validators and select invalid instances."""
|
||||||
|
# Get the errored instances
|
||||||
|
failed = []
|
||||||
|
for result in context.data["results"]:
|
||||||
|
if (
|
||||||
|
result["error"] is None
|
||||||
|
or result["instance"] is None
|
||||||
|
or result["instance"] in failed
|
||||||
|
or result["plugin"] != plugin
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
failed.append(result["instance"])
|
||||||
|
|
||||||
|
# Apply pyblish.logic to get the instances for the plug-in
|
||||||
|
instances = pyblish.api.instances_by_plugin(failed, plugin)
|
||||||
|
|
||||||
|
if instances:
|
||||||
|
self.log.info(
|
||||||
|
"Selecting invalid nodes: %s" % ", ".join(
|
||||||
|
[str(x) for x in instances]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.select(instances)
|
||||||
|
else:
|
||||||
|
self.log.info("No invalid nodes found.")
|
||||||
|
self.deselect()
|
||||||
|
|
||||||
|
def select(self, instances):
|
||||||
|
avalon.nuke.lib.select_nodes(
|
||||||
|
[nuke.toNode(str(x)) for x in instances]
|
||||||
|
)
|
||||||
|
|
||||||
|
def deselect(self):
|
||||||
|
avalon.nuke.lib.reset_selection()
|
||||||
|
|
||||||
|
|
||||||
|
class RepairSelectInvalidInstances(pyblish.api.Action):
|
||||||
|
"""Repair the instance asset."""
|
||||||
|
|
||||||
|
label = "Repair"
|
||||||
|
icon = "wrench"
|
||||||
|
on = "failed"
|
||||||
|
|
||||||
|
def process(self, context, plugin):
|
||||||
|
# Get the errored instances
|
||||||
|
failed = []
|
||||||
|
for result in context.data["results"]:
|
||||||
|
if (
|
||||||
|
result["error"] is None
|
||||||
|
or result["instance"] is None
|
||||||
|
or result["instance"] in failed
|
||||||
|
or result["plugin"] != plugin
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
failed.append(result["instance"])
|
||||||
|
|
||||||
|
# Apply pyblish.logic to get the instances for the plug-in
|
||||||
|
instances = pyblish.api.instances_by_plugin(failed, plugin)
|
||||||
|
|
||||||
|
context_asset = context.data["assetEntity"]["name"]
|
||||||
|
for instance in instances:
|
||||||
|
origin_node = instance[0]
|
||||||
|
nuke_api.lib.recreate_instance(
|
||||||
|
origin_node, avalon_data={"asset": context_asset}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ValidateInstanceInContext(pyblish.api.InstancePlugin):
|
||||||
|
"""Validator to check if instance asset match context asset.
|
||||||
|
|
||||||
|
When working in per-shot style you always publish data in context of
|
||||||
|
current asset (shot). This validator checks if this is so. It is optional
|
||||||
|
so it can be disabled when needed.
|
||||||
|
|
||||||
|
Action on this validator will select invalid instances in Outliner.
|
||||||
|
"""
|
||||||
|
|
||||||
|
order = openpype.api.ValidateContentsOrder
|
||||||
|
label = "Instance in same Context"
|
||||||
|
hosts = ["nuke"]
|
||||||
|
actions = [SelectInvalidInstances, RepairSelectInvalidInstances]
|
||||||
|
optional = True
|
||||||
|
|
||||||
|
def process(self, instance):
|
||||||
|
asset = instance.data.get("asset")
|
||||||
|
context_asset = instance.context.data["assetEntity"]["name"]
|
||||||
|
msg = "{} has asset {}".format(instance.name, asset)
|
||||||
|
assert asset == context_asset, msg
|
||||||
|
|
@ -156,6 +156,11 @@
|
||||||
"CollectMayaRender": {
|
"CollectMayaRender": {
|
||||||
"sync_workfile_version": false
|
"sync_workfile_version": false
|
||||||
},
|
},
|
||||||
|
"ValidateInstanceInContext": {
|
||||||
|
"enabled": true,
|
||||||
|
"optional": true,
|
||||||
|
"active": true
|
||||||
|
},
|
||||||
"ValidateContainers": {
|
"ValidateContainers": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@
|
||||||
"render"
|
"render"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"ValidateInstanceInContext": {
|
||||||
|
"enabled": true,
|
||||||
|
"optional": true,
|
||||||
|
"active": true
|
||||||
|
},
|
||||||
"ValidateContainers": {
|
"ValidateContainers": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,16 @@
|
||||||
"type": "label",
|
"type": "label",
|
||||||
"label": "Validators"
|
"label": "Validators"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "schema_template",
|
||||||
|
"name": "template_publish_plugin",
|
||||||
|
"template_data": [
|
||||||
|
{
|
||||||
|
"key": "ValidateInstanceInContext",
|
||||||
|
"label": "Validate Instance In Context"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "schema_template",
|
"type": "schema_template",
|
||||||
"name": "template_publish_plugin",
|
"name": "template_publish_plugin",
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,16 @@
|
||||||
"type": "label",
|
"type": "label",
|
||||||
"label": "Validators"
|
"label": "Validators"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "schema_template",
|
||||||
|
"name": "template_publish_plugin",
|
||||||
|
"template_data": [
|
||||||
|
{
|
||||||
|
"key": "ValidateInstanceInContext",
|
||||||
|
"label": "Validate Instance In Context"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "schema_template",
|
"type": "schema_template",
|
||||||
"name": "template_publish_plugin",
|
"name": "template_publish_plugin",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue