OP-2414 - merged Creators into one better importable

This commit is contained in:
Petr Kalis 2022-02-04 18:03:16 +01:00
parent c384f0aadf
commit e5fab7d121
3 changed files with 68 additions and 72 deletions

View file

@ -3,11 +3,11 @@
Anything that isn't defined here is INTERNAL and unreliable for external use.
"""
from . import plugin
from .pipeline import (
ls,
install,
Creator,
list_instances,
remove_instance,
select_instance,
@ -52,7 +52,6 @@ __all__ = [
# pipeline
"ls",
"install",
"Creator",
"list_instances",
"remove_instance",
"select_instance",

View file

@ -319,73 +319,6 @@ def select_instance(instance):
harmony.select_nodes([instance.get("uuid")])
class Creator(avalon.api.Creator):
"""Creator plugin to create instances in Harmony.
By default a Composite node is created to support any number of nodes in
an instance, but any node type is supported.
If the selection is used, the selected nodes will be connected to the
created node.
"""
node_type = "COMPOSITE"
def setup_node(self, node):
"""Prepare node as container.
Args:
node (str): Path to node.
"""
harmony.send(
{
"function": "AvalonHarmony.setupNodeForCreator",
"args": node
}
)
def process(self):
"""Plugin entry point."""
existing_node_names = harmony.send(
{
"function": "AvalonHarmony.getNodesNamesByType",
"args": self.node_type
})["result"]
# Dont allow instances with the same name.
msg = "Instance with name \"{}\" already exists.".format(self.name)
for name in existing_node_names:
if self.name.lower() == name.lower():
harmony.send(
{
"function": "AvalonHarmony.message", "args": msg
}
)
return False
with harmony.maintained_selection() as selection:
node = None
if (self.options or {}).get("useSelection") and selection:
node = harmony.send(
{
"function": "AvalonHarmony.createContainer",
"args": [self.name, self.node_type, selection[-1]]
}
)["result"]
else:
node = harmony.send(
{
"function": "AvalonHarmony.createContainer",
"args": [self.name, self.node_type]
}
)["result"]
harmony.imprint(node, self.data)
self.setup_node(node)
return node
def containerise(name,
namespace,
node,

View file

@ -1,6 +1,70 @@
from openpype.hosts.harmony.api import Creator
import avalon.api
from openpype.api import PypeCreatorMixin
import openpype.hosts.harmony.api as harmony
class Creator(PypeCreatorMixin, Creator):
pass
class Creator(PypeCreatorMixin, avalon.api.Creator):
"""Creator plugin to create instances in Harmony.
By default a Composite node is created to support any number of nodes in
an instance, but any node type is supported.
If the selection is used, the selected nodes will be connected to the
created node.
"""
node_type = "COMPOSITE"
def setup_node(self, node):
"""Prepare node as container.
Args:
node (str): Path to node.
"""
harmony.send(
{
"function": "AvalonHarmony.setupNodeForCreator",
"args": node
}
)
def process(self):
"""Plugin entry point."""
existing_node_names = harmony.send(
{
"function": "AvalonHarmony.getNodesNamesByType",
"args": self.node_type
})["result"]
# Dont allow instances with the same name.
msg = "Instance with name \"{}\" already exists.".format(self.name)
for name in existing_node_names:
if self.name.lower() == name.lower():
harmony.send(
{
"function": "AvalonHarmony.message", "args": msg
}
)
return False
with harmony.maintained_selection() as selection:
node = None
if (self.options or {}).get("useSelection") and selection:
node = harmony.send(
{
"function": "AvalonHarmony.createContainer",
"args": [self.name, self.node_type, selection[-1]]
}
)["result"]
else:
node = harmony.send(
{
"function": "AvalonHarmony.createContainer",
"args": [self.name, self.node_type]
}
)["result"]
harmony.imprint(node, self.data)
self.setup_node(node)
return node