Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto connect to composition node #23

2 changes: 1 addition & 1 deletion client/ayon_harmony/api/js/AyonHarmonyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ AyonHarmonyAPI.setupNodeForCreator = function(node) {
* @return {array} Node names.
*/
AyonHarmonyAPI.getNodesNamesByType = function(nodeType) {
var nodes = node.getNodes(nodeType);
var nodes = node.getNodes([nodeType]);
var nodeNames = [];
for (var i = 0; i < nodes.length; ++i) {
nodeNames.push(node.getName(nodes[i]));
Expand Down
35 changes: 34 additions & 1 deletion client/ayon_harmony/api/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from ayon_core.pipeline import LegacyCreator
import re

from ayon_core.pipeline import LegacyCreator, CreatorError
import ayon_harmony.api as harmony


Expand All @@ -14,6 +16,10 @@ class Creator(LegacyCreator):

defaults = ["Main"]
node_type = "COMPOSITE"
settings_category = "harmony"

auto_connect = False
composition_node_pattern = ""

def setup_node(self, node):
"""Prepare node as container.
Expand Down Expand Up @@ -57,6 +63,33 @@ def process(self):
"args": [self.name, self.node_type, selection[-1]]
}
)["result"]
elif (self.auto_connect):
existing_comp_names = harmony.send(
{
"function": "AyonHarmonyAPI.getNodesNamesByType",
"args": "COMPOSITE"
})["result"]
name_pattern = self.composition_node_pattern
if not name_pattern:
raise CreatorError("Composition name regex pattern "
"must be filled")
compiled_pattern = re.compile(name_pattern)
matching_nodes = [name for name in existing_comp_names
if compiled_pattern.match(name)]
if len(matching_nodes) > 1:
self.log.warning("Multiple composition node found, "
"picked first")
elif len(matching_nodes) <= 0:
raise CreatorError("No matching composition "
"node found")
node_name = f"/Top/{matching_nodes[0]}"

node = harmony.send(
{
"function": "AyonHarmonyAPI.createContainer",
"args": [self.name, self.node_type, node_name]
}
)["result"]
else:
node = harmony.send(
{
Expand Down
2 changes: 1 addition & 1 deletion client/ayon_harmony/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""Package declaring AYON addon 'harmony' version."""
__version__ = "0.2.2+dev"
__version__ = "0.2.2+dev.1"
2 changes: 1 addition & 1 deletion package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "harmony"
title = "Harmony"
version = "0.2.2+dev"
version = "0.2.2+dev.1"
client_dir = "ayon_harmony"
app_host_name = "harmony"

Expand Down
49 changes: 49 additions & 0 deletions server/settings/creator_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from ayon_server.settings import BaseSettingsModel, SettingsField


class CreateRenderPluginModel(BaseSettingsModel):
enabled: bool = SettingsField(True, title="Enabled")
active_on_create: bool = SettingsField(True, title="Active by default")
default_variants: list[str] = SettingsField(
default_factory=list,
title="Default Variants"
)
auto_connect: bool = SettingsField(False,
title="Auto connect to Composite node")
composition_node_pattern: str = SettingsField(
"Composition",
title="Regex pattern for Composite node name",
description="Provide regex pattern to find Composite node to "
"connect newly Write node to"
)


class HarmonyCreatePlugins(BaseSettingsModel):
CreateRender: CreateRenderPluginModel = SettingsField(
title="Render",
default_factory=CreateRenderPluginModel,
)
CreateFarmRender: CreateRenderPluginModel = SettingsField(
title="Render on Farm",
default_factory=CreateRenderPluginModel,
)


DEFAULT_CREATE_SETTINGS = {
"CreateRender": {
"enabled": True,
"default_variants": [
"Main"
],
"auto_connect": False,
"composition_node_pattern": "Composite"
},
"CreateFarmRender": {
"enabled": True,
"default_variants": [
"Main"
],
"auto_connect": False,
"composition_node_pattern": "Composite"
}
}
5 changes: 5 additions & 0 deletions server/settings/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ayon_server.settings import BaseSettingsModel, SettingsField

from .imageio import HarmonyImageIOModel
from .creator_plugins import HarmonyCreatePlugins
from .publish_plugins import HarmonyPublishPlugins


Expand All @@ -11,6 +12,10 @@ class HarmonySettings(BaseSettingsModel):
default_factory=HarmonyImageIOModel,
title="OCIO config"
)
create: HarmonyCreatePlugins = SettingsField(
default_factory=HarmonyCreatePlugins,
title="Creator plugins"
)
publish: HarmonyPublishPlugins = SettingsField(
default_factory=HarmonyPublishPlugins,
title="Publish plugins"
Expand Down
Loading