Harmony - refactor of instance[0] for Pype3

Better looking and clearer handling of nodes
Small fixes (path of PypeHarmony)
This commit is contained in:
Petr Kalis 2021-02-19 19:11:02 +01:00
parent 4d02523093
commit 5762f205af
9 changed files with 35 additions and 32 deletions

View file

@ -60,6 +60,8 @@ def get_asset_settings():
"fps": fps,
"frameStart": frame_start,
"frameEnd": frame_end,
"handleStart": handle_start,
"handleEnd": handle_end,
"resolutionWidth": resolution_width,
"resolutionHeight": resolution_height
}
@ -152,13 +154,14 @@ def application_launch():
# It is now moved so it it manually called.
# ensure_scene_settings()
# check_inventory()
pype_harmony_path = Path(__file__).parent / "js" / "PypeHarmony.js"
# fills PYPE_HARMONY_JS
pype_harmony_path = Path(__file__).parent.parent / "js" / "PypeHarmony.js"
pype_harmony_js = pype_harmony_path.read_text()
# go through js/creators, loaders and publish folders and load all scripts
script = ""
for item in ["creators", "loaders", "publish"]:
dir_to_scan = Path(__file__).parent / "js" / item
dir_to_scan = Path(__file__).parent.parent / "js" / item
for child in dir_to_scan.iterdir():
script += child.read_text()
@ -212,19 +215,15 @@ def uninstall():
def on_pyblish_instance_toggled(instance, old_value, new_value):
"""Toggle node enabling on instance toggles."""
try:
node = instance[0] # regular instance
except IndexError:
try:
node = instance.data["setMembers"][0] # for HarmonyRenderInstance
except IndexError:
print(f"Instance '{instance}' is missing node")
return
node = None
if instance.data.get("setMembers"):
node = instance.data["setMembers"][0]
harmony.send(
{
"function": "PypeHarmony.toggleInstance",
"args": [node, new_value]
}
)
if node:
harmony.send(
{
"function": "PypeHarmony.toggleInstance",
"args": [node, new_value]
}
)

View file

@ -54,8 +54,8 @@ class CollectInstances(pyblish.api.ContextPlugin):
continue
instance = context.create_instance(node.split("/")[-1])
instance.append(node)
instance.data.update(data)
instance.data["setMembers"] = [node]
instance.data["publish"] = harmony.send(
{"function": "node.getEnable", "args": [node]}
)["result"]

View file

@ -7,7 +7,6 @@ from PIL import Image, ImageDraw, ImageFont
from avalon import harmony
import pype.api
import pype.hosts.harmony
class ExtractPalette(pype.api.Extractor):

View file

@ -47,7 +47,8 @@ class ExtractRender(pyblish.api.InstancePlugin):
harmony.send(
{
"function": func,
"args": [instance[0], path + "/" + instance.data["name"]]
"args": [instance.data["setMembers"][0],
path + "/" + instance.data["name"]]
}
)
harmony.save_scene()
@ -75,7 +76,7 @@ class ExtractRender(pyblish.api.InstancePlugin):
collections, remainder = clique.assemble(files, minimum_items=1)
assert not remainder, (
"There should not be a remainder for {0}: {1}".format(
instance[0], remainder
instance.data["setMembers"][0], remainder
)
)
self.log.debug(collections)

View file

@ -23,7 +23,7 @@ class ExtractTemplate(pype.api.Extractor):
self.log.info(f"Outputting template to {staging_dir}")
dependencies = []
self.get_dependencies(instance[0], dependencies)
self.get_dependencies(instance.data["setMembers"][0], dependencies)
# Get backdrops.
backdrops = {}
@ -46,11 +46,11 @@ class ExtractTemplate(pype.api.Extractor):
dependencies.append(node)
# Make sure we dont export the instance node.
if instance[0] in dependencies:
dependencies.remove(instance[0])
if instance.data["setMembers"][0] in dependencies:
dependencies.remove(instance.data["setMembers"][0])
# Export template.
pype.hosts.harmony.export_template(
pype.hosts.harmony.api.export_template(
unique_backdrops, dependencies, filepath
)

View file

@ -5,8 +5,6 @@ import shutil
from zipfile import ZipFile
import pype.api
from avalon import harmony
import pype.hosts.harmony
class ExtractWorkfile(pype.api.Extractor):

View file

@ -19,6 +19,12 @@ class ValidateAudio(pyblish.api.InstancePlugin):
optional = True
def process(self, instance):
node = None
if instance.data.get("setMembers"):
node = instance.data["setMembers"][0]
if not node:
return
# Collect scene data.
func = """function func(write_node)
{
@ -29,7 +35,7 @@ class ValidateAudio(pyblish.api.InstancePlugin):
func
"""
result = harmony.send(
{"function": func, "args": [instance[0]]}
{"function": func, "args": [node]}
)["result"]
audio_path = result[0]

View file

@ -25,9 +25,9 @@ class ValidateInstanceRepair(pyblish.api.Action):
instances = pyblish.api.instances_by_plugin(failed, plugin)
for instance in instances:
data = harmony.read(instance[0])
data = harmony.read(instance.data["setMembers"][0])
data["asset"] = os.environ["AVALON_ASSET"]
harmony.imprint(instance[0], data)
harmony.imprint(instance.data["setMembers"][0], data)
class ValidateInstance(pyblish.api.InstancePlugin):

View file

@ -18,12 +18,12 @@ class ValidateSceneSettingsRepair(pyblish.api.Action):
def process(self, context, plugin):
"""Repair action entry point."""
expected = pype.hosts.harmony.get_asset_settings()
expected = pype.hosts.harmony.api.get_asset_settings()
asset_settings = _update_frames(dict.copy(expected))
asset_settings["frameStart"] = 1
asset_settings["frameEnd"] = asset_settings["frameEnd"] + \
asset_settings["handleEnd"]
pype.hosts.harmony.set_scene_settings(asset_settings)
pype.hosts.harmony.api.set_scene_settings(asset_settings)
if not os.path.exists(context.data["scenePath"]):
self.log.info("correcting scene name")
scene_dir = os.path.dirname(context.data["currentFile"])
@ -48,7 +48,7 @@ class ValidateSceneSettings(pyblish.api.InstancePlugin):
def process(self, instance):
"""Plugin entry point."""
expected_settings = pype.hosts.harmony.get_asset_settings()
expected_settings = pype.hosts.harmony.api.get_asset_settings()
self.log.info(expected_settings)
expected_settings = _update_frames(dict.copy(expected_settings))