fixing harmony js function signatures

This commit is contained in:
Ondrej Samohel 2020-10-05 13:58:57 +02:00
parent df5db0fbf0
commit 496a29ba99
No known key found for this signature in database
GPG key ID: 8A29C663C672C2B7
14 changed files with 89 additions and 67 deletions

View file

@ -14,7 +14,9 @@ signature = str(uuid4())
def set_scene_settings(settings):
func = """function %s_func(args)
signature = harmony.signature("set_scene_settings")
func = """function %s(args)
{
if (args[0]["fps"])
{
@ -41,7 +43,7 @@ def set_scene_settings(settings):
)
}
}
%s_func
%s
""" % (signature, signature)
harmony.send({"function": func, "args": [settings]})
@ -62,7 +64,7 @@ def get_asset_settings():
"resolutionHeight": resolution_height
}
harmony_config = config.get_presets().["harmony"]["general"]
harmony_config = config.get_presets()["harmony"]["general"]
skip_resolution_check = harmony_config.get(["skip_resolution_check"], [])
if os.getenv('AVALON_TASK') in skip_resolution_check:
@ -121,15 +123,17 @@ def check_inventory():
outdated_containers.append(container)
# Colour nodes.
func = """function %s_func(args){
sig = harmony.signature("set_color")
func = """function %s(args){
for( var i =0; i <= args[0].length - 1; ++i)
{
var red_color = new ColorRGBA(255, 0, 0, 255);
node.setColor(args[0][i], red_color);
}
}
%s_func
""" % (signature, signature)
%s
""" % (sig, sig)
outdated_nodes = []
for container in outdated_containers:
if container["loader"] == "ImageSequenceLoader":
@ -158,7 +162,9 @@ def application_launch():
def export_template(backdrops, nodes, filepath):
func = """function %s_func(args)
sig = harmony.signature("set_color")
func = """function %s(args)
{
var temp_node = node.add("Top", "temp_note", "NOTE", 0, 0, 0);
@ -193,8 +199,8 @@ def export_template(backdrops, nodes, filepath):
Action.perform("onActionUpToParent()", "Node View");
node.deleteNode(template_group, true, true);
}
%s_func
""" % (signature, signature)
%s
""" % (sig, sig)
harmony.send({
"function": func,
"args": [
@ -235,12 +241,14 @@ def install():
def on_pyblish_instance_toggled(instance, old_value, new_value):
"""Toggle node enabling on instance toggles."""
func = """function %s_func(args)
sig = harmony.signature("enable_node")
func = """function %s(args)
{
node.setEnable(args[0], args[1])
}
%s_func
""" % (signature, signature)
%s
""" % (sig, sig)
try:
harmony.send(
{"function": func, "args": [instance[0], new_value]}

View file

@ -13,13 +13,14 @@ class CreateRender(harmony.Creator):
super(CreateRender, self).__init__(*args, **kwargs)
def setup_node(self, node):
func = """function func(args)
sig = harmony.signature()
func = """function %s(args)
{
node.setTextAttr(args[0], "DRAWING_TYPE", 1, "PNG4");
node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]);
node.setTextAttr(args[0], "MOVIE_PATH", 1, args[1]);
}
func
"""
%s
""" % (sig, sig)
path = "{0}/{0}".format(node.split("/")[-1])
harmony.send({"function": func, "args": [node, path]})

View file

@ -1,6 +1,6 @@
from avalon import api, harmony
sig = harmony.signature()
func = """
function getUniqueColumnName( column_prefix )
{
@ -18,14 +18,14 @@ function getUniqueColumnName( column_prefix )
return column_name;
}
function func(args)
function %s(args)
{
var uniqueColumnName = getUniqueColumnName(args[0]);
column.add(uniqueColumnName , "SOUND");
column.importSound(uniqueColumnName, 1, args[1]);
}
func
"""
%s
""" % (sig, sig)
class ImportAudioLoader(api.Loader):

View file

@ -324,9 +324,9 @@ class BackgroundLoader(api.Loader):
)["result"]
container['nodes'].append(read_node)
# Colour node.
func = """function func(args){
sig = harmony.signature("set_color")
func = """function %s(args){
for( var i =0; i <= args[0].length - 1; ++i)
{
var red_color = new ColorRGBA(255, 0, 0, 255);
@ -339,8 +339,8 @@ class BackgroundLoader(api.Loader):
}
}
}
func
"""
%s
""" % (sig, sig)
if pype.lib.is_latest(representation):
harmony.send({"function": func, "args": [node, "green"]})
else:

View file

@ -301,7 +301,8 @@ class ImageSequenceLoader(api.Loader):
)
# Colour node.
func = """function func(args){
sig = harmony.signature("copyFile")
func = """function %s(args){
for( var i =0; i <= args[0].length - 1; ++i)
{
var red_color = new ColorRGBA(255, 0, 0, 255);
@ -314,8 +315,8 @@ class ImageSequenceLoader(api.Loader):
}
}
}
func
"""
%s
""" % (sig, sig)
if pype.lib.is_latest(representation):
harmony.send({"function": func, "args": [node, "green"]})
else:

View file

@ -21,15 +21,16 @@ class ImportTemplateLoader(api.Loader):
with zipfile.ZipFile(zip_file, "r") as zip_ref:
zip_ref.extractall(template_path)
func = """function func(args)
sig = harmony.signature("paste")
func = """function %s(args)
{
var template_path = args[0];
var drag_object = copyPaste.pasteTemplateIntoGroup(
template_path, "Top", 1
);
}
func
"""
%s
""" % (sig, sig)
harmony.send({"function": func, "args": [template_path]})

View file

@ -13,15 +13,16 @@ class CollectCurrentFile(pyblish.api.ContextPlugin):
def process(self, context):
"""Inject the current working file"""
func = """function func()
sig = harmony.signature()
func = """function %s()
{
return (
scene.currentProjectPath() + "/" +
scene.currentVersionName() + ".xstage"
);
}
func
"""
%s
""" % (sig, sig)
current_file = harmony.send({"function": func})["result"]
context.data["currentFile"] = os.path.normpath(current_file)

View file

@ -13,7 +13,8 @@ class CollectPalettes(pyblish.api.ContextPlugin):
hosts = ["harmony"]
def process(self, context):
func = """function func()
sig = harmony.signature()
func = """function %s()
{
var palette_list = PaletteObjectManager.getScenePaletteList();
@ -26,8 +27,8 @@ class CollectPalettes(pyblish.api.ContextPlugin):
return palettes;
}
func
"""
%s
""" % (sig, sig)
palettes = harmony.send({"function": func})["result"]
for name, id in palettes.items():

View file

@ -13,14 +13,15 @@ class ExtractPalette(pype.api.Extractor):
families = ["harmony.palette"]
def process(self, instance):
func = """function func(args)
sig = harmony.signature()
func = """function %s(args)
{
var palette_list = PaletteObjectManager.getScenePaletteList();
var palette = palette_list.getPaletteById(args[0]);
return (palette.getPath() + "/" + palette.getName() + ".plt");
}
func
"""
%s
""" % (sig, sig)
palette_file = harmony.send(
{"function": func, "args": [instance.data["id"]]}
)["result"]

View file

@ -21,7 +21,8 @@ class ExtractRender(pyblish.api.InstancePlugin):
def process(self, instance):
# Collect scene data.
func = """function func(write_node)
sig = harmony.signature()
func = """function %s(write_node)
{
return [
about.getApplicationPath(),
@ -33,8 +34,8 @@ class ExtractRender(pyblish.api.InstancePlugin):
sound.getSoundtrackAll().path()
]
}
func
"""
%s
""" % (sig, sig)
result = harmony.send(
{"function": func, "args": [instance[0]]}
)["result"]
@ -50,12 +51,13 @@ class ExtractRender(pyblish.api.InstancePlugin):
# Set output path to temp folder.
path = tempfile.mkdtemp()
func = """function func(args)
sig = harmony.signature()
func = """function %s(args)
{
node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]);
}
func
"""
%s
""" % (sig, sig)
result = harmony.send(
{
"function": func,

View file

@ -2,7 +2,7 @@ import os
import shutil
import pype.api
import avalon.harmony
from avalon import harmony
import pype.hosts.harmony
@ -30,7 +30,7 @@ class ExtractTemplate(pype.api.Extractor):
unique_backdrops = [backdrops[x] for x in set(backdrops.keys())]
# Get non-connected nodes within backdrops.
all_nodes = avalon.harmony.send(
all_nodes = harmony.send(
{"function": "node.subNodes", "args": ["Top"]}
)["result"]
for node in [x for x in all_nodes if x not in dependencies]:
@ -66,7 +66,8 @@ class ExtractTemplate(pype.api.Extractor):
instance.data["representations"] = [representation]
def get_backdrops(self, node):
func = """function func(probe_node)
sig = harmony.signature()
func = """function %s(probe_node)
{
var backdrops = Backdrop.backdrops("Top");
var valid_backdrops = [];
@ -92,14 +93,15 @@ class ExtractTemplate(pype.api.Extractor):
}
return valid_backdrops;
}
func
"""
return avalon.harmony.send(
%s
""" % (sig, sig)
return harmony.send(
{"function": func, "args": [node]}
)["result"]
def get_dependencies(self, node, dependencies):
func = """function func(args)
sig = harmony.signature()
func = """function %s(args)
{
var target_node = args[0];
var numInput = node.numberOfInputPorts(target_node);
@ -110,10 +112,10 @@ class ExtractTemplate(pype.api.Extractor):
}
return dependencies;
}
func
"""
%s
""" % (sig, sig)
current_dependencies = avalon.harmony.send(
current_dependencies = harmony.send(
{"function": func, "args": [node]}
)["result"]

View file

@ -2,7 +2,7 @@ import os
import shutil
import pype.api
import avalon.harmony
from avalon import harmony
import pype.hosts.harmony
@ -15,10 +15,10 @@ class ExtractWorkfile(pype.api.Extractor):
def process(self, instance):
# Export template.
backdrops = avalon.harmony.send(
backdrops = harmony.send(
{"function": "Backdrop.backdrops", "args": ["Top"]}
)["result"]
nodes = avalon.harmony.send(
nodes = harmony.send(
{"function": "node.subNodes", "args": ["Top"]}
)["result"]
staging_dir = self.staging_dir(instance)

View file

@ -1,14 +1,17 @@
import json
import os
import pyblish.api
import avalon.harmony
import pype.hosts.harmony
from avalon import harmony
class ValidateAudio(pyblish.api.InstancePlugin):
"""Ensures that there is an audio file in the scene. If you are sure that you want to send render without audio, you can disable this validator before clicking on "publish" """
"""Ensures that there is an audio file in the scene.
If you are sure that you want to send render without audio, you can
disable this validator before clicking on "publish"
"""
order = pyblish.api.ValidatorOrder
label = "Validate Audio"
@ -26,7 +29,7 @@ class ValidateAudio(pyblish.api.InstancePlugin):
}
func
"""
result = avalon.harmony.send(
result = harmony.send(
{"function": func, "args": [instance[0]]}
)["result"]

View file

@ -2,7 +2,7 @@ import json
import pyblish.api
import avalon.harmony
from avalon import harmony
import pype.hosts.harmony
@ -46,7 +46,8 @@ class ValidateSceneSettings(pyblish.api.InstancePlugin):
for string in self.frame_check_filter):
expected_settings.pop("frameEnd")
func = """function func()
sig = harmony.signature()
func = """function %s()
{
return {
"fps": scene.getFrameRate(),
@ -56,9 +57,9 @@ class ValidateSceneSettings(pyblish.api.InstancePlugin):
"resolutionHeight": scene.defaultResolutionY()
};
}
func
"""
current_settings = avalon.harmony.send({"function": func})["result"]
%s
""" % (sig, sig)
current_settings = harmony.send({"function": func})["result"]
invalid_settings = []
for key, value in expected_settings.items():