Skip to content

Commit

Permalink
Merge pull request #23 from ynput/enhancement/AY-7307_Harmony-Look-fo…
Browse files Browse the repository at this point in the history
…r-composition-node-and-connect-automatically-if-not-Use-selection

Auto connect to composition node
  • Loading branch information
kalisp authored Jan 13, 2025
2 parents 566f5b9 + 723fd0f commit 466ba8c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 4 deletions.
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

0 comments on commit 466ba8c

Please sign in to comment.