mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 13:24:54 +01:00
Merge pull request #2 from BigRoy/fusion-new-publisher
Fusion: New Publisher tweaks to PR
This commit is contained in:
commit
ddcbca07bd
3 changed files with 58 additions and 78 deletions
|
|
@ -155,10 +155,12 @@ class FusionHost(HostBase, IWorkfileHost, ILoadHost, IPublishHost):
|
|||
return ls()
|
||||
|
||||
def update_context_data(self, data, changes):
|
||||
print(data, changes)
|
||||
comp = get_current_comp()
|
||||
comp.SetData("openpype", data)
|
||||
|
||||
def get_context_data(self):
|
||||
return {}
|
||||
comp = get_current_comp()
|
||||
return comp.GetData("openpype") or {}
|
||||
|
||||
|
||||
def on_pyblish_instance_toggled(instance, old_value, new_value):
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from openpype.pipeline import (
|
|||
Creator,
|
||||
CreatedInstance
|
||||
)
|
||||
from openpype.client import get_asset_by_name
|
||||
|
||||
|
||||
class CreateSaver(Creator):
|
||||
|
|
@ -87,15 +88,10 @@ class CreateSaver(Creator):
|
|||
return qtawesome.icon("fa.eye", color="white")
|
||||
|
||||
def update_instances(self, update_list):
|
||||
for update in update_list:
|
||||
instance = update.instance
|
||||
for created_inst, _changes in update_list:
|
||||
|
||||
# Get the new values after the changes by key, ignore old value
|
||||
new_data = {
|
||||
key: new for key, (_old, new) in update.changes.items()
|
||||
}
|
||||
|
||||
tool = instance.transient_data["tool"]
|
||||
new_data = created_inst.data_to_store()
|
||||
tool = created_inst.transient_data["tool"]
|
||||
self._update_tool_with_data(tool, new_data)
|
||||
self._imprint(tool, new_data)
|
||||
|
||||
|
|
@ -150,14 +146,22 @@ class CreateSaver(Creator):
|
|||
asset = legacy_io.Session["AVALON_ASSET"]
|
||||
task = legacy_io.Session["AVALON_TASK"]
|
||||
|
||||
asset_doc = get_asset_by_name(project_name=project,
|
||||
asset_name=asset)
|
||||
|
||||
path = tool["Clip"][comp.TIME_UNDEFINED]
|
||||
fname = os.path.basename(path)
|
||||
fname, _ext = os.path.splitext(fname)
|
||||
subset = fname.rstrip(".")
|
||||
variant = fname.rstrip(".")
|
||||
subset = self.get_subset_name(
|
||||
variant=variant,
|
||||
task_name=task,
|
||||
asset_doc=asset_doc,
|
||||
project_name=project,
|
||||
)
|
||||
|
||||
attrs = tool.GetAttrs()
|
||||
passthrough = attrs["TOOLB_PassThrough"]
|
||||
variant = subset[len("render"):]
|
||||
return {
|
||||
# Required data
|
||||
"project": project,
|
||||
|
|
|
|||
|
|
@ -13,17 +13,6 @@ from openpype.pipeline import (
|
|||
)
|
||||
|
||||
|
||||
def flatten_dict(d, parent_key=None, separator="."):
|
||||
items = []
|
||||
for key, v in d.items():
|
||||
new_key = parent_key + separator + key if parent_key else key
|
||||
if isinstance(v, collections.MutableMapping):
|
||||
items.extend(flatten_dict(v, new_key, separator=separator).items())
|
||||
else:
|
||||
items.append((new_key, v))
|
||||
return dict(items)
|
||||
|
||||
|
||||
class FusionWorkfileCreator(AutoCreator):
|
||||
identifier = "workfile"
|
||||
family = "workfile"
|
||||
|
|
@ -33,7 +22,7 @@ class FusionWorkfileCreator(AutoCreator):
|
|||
|
||||
create_allow_context_change = False
|
||||
|
||||
data_key = "openpype.workfile"
|
||||
data_key = "openpype_workfile"
|
||||
|
||||
def collect_instances(self):
|
||||
|
||||
|
|
@ -53,21 +42,17 @@ class FusionWorkfileCreator(AutoCreator):
|
|||
self._add_instance_to_context(instance)
|
||||
|
||||
def update_instances(self, update_list):
|
||||
for update in update_list:
|
||||
instance = update.instance
|
||||
comp = instance.transient_data["comp"]
|
||||
for created_inst, _changes in update_list:
|
||||
comp = created_inst.transient_data["comp"]
|
||||
if not hasattr(comp, "SetData"):
|
||||
# Comp is not alive anymore, likely closed by the user
|
||||
self.log.error("Workfile comp not found for existing instance."
|
||||
" Comp might have been closed in the meantime.")
|
||||
continue
|
||||
|
||||
# TODO: It appears sometimes this could be 'nested'
|
||||
# Get the new values after the changes by key, ignore old value
|
||||
new_data = {
|
||||
key: new for key, (_old, new) in update.changes.items()
|
||||
}
|
||||
self._imprint(comp, new_data)
|
||||
# Imprint data into the comp
|
||||
data = created_inst.data_to_store()
|
||||
comp.SetData(self.data_key, data)
|
||||
|
||||
def create(self, options=None):
|
||||
|
||||
|
|
@ -76,61 +61,50 @@ class FusionWorkfileCreator(AutoCreator):
|
|||
self.log.error("Unable to find current comp")
|
||||
return
|
||||
|
||||
# TODO: Is this really necessary?
|
||||
# Force kill any existing "workfile" instances
|
||||
existing_instance = None
|
||||
for instance in self.create_context.instances:
|
||||
if instance.family == self.family:
|
||||
self.log.debug(f"Removing instance: {instance}")
|
||||
self._remove_instance_from_context(instance)
|
||||
existing_instance = instance
|
||||
break
|
||||
|
||||
project_name = legacy_io.Session["AVALON_PROJECT"]
|
||||
asset_name = legacy_io.Session["AVALON_ASSET"]
|
||||
task_name = legacy_io.Session["AVALON_TASK"]
|
||||
host_name = legacy_io.Session["AVALON_APP"]
|
||||
|
||||
asset_doc = get_asset_by_name(project_name, asset_name)
|
||||
subset_name = self.get_subset_name(
|
||||
self.default_variant, task_name, asset_doc,
|
||||
project_name, host_name
|
||||
)
|
||||
data = {
|
||||
"asset": asset_name,
|
||||
"task": task_name,
|
||||
"variant": self.default_variant
|
||||
}
|
||||
data.update(self.get_dynamic_data(
|
||||
self.default_variant,
|
||||
task_name,
|
||||
asset_doc,
|
||||
project_name,
|
||||
host_name,
|
||||
data
|
||||
))
|
||||
if existing_instance is None:
|
||||
asset_doc = get_asset_by_name(project_name, asset_name)
|
||||
subset_name = self.get_subset_name(
|
||||
self.default_variant, task_name, asset_doc,
|
||||
project_name, host_name
|
||||
)
|
||||
data = {
|
||||
"asset": asset_name,
|
||||
"task": task_name,
|
||||
"variant": self.default_variant
|
||||
}
|
||||
data.update(self.get_dynamic_data(
|
||||
self.default_variant, task_name, asset_doc,
|
||||
project_name, host_name, None
|
||||
))
|
||||
|
||||
instance = CreatedInstance(
|
||||
family=self.family,
|
||||
subset_name=subset_name,
|
||||
data=data,
|
||||
creator=self
|
||||
)
|
||||
instance.transient_data["comp"] = comp
|
||||
self._add_instance_to_context(instance)
|
||||
new_instance = CreatedInstance(
|
||||
self.family, subset_name, data, self
|
||||
)
|
||||
self._add_instance_to_context(new_instance)
|
||||
|
||||
self._imprint(comp, data)
|
||||
elif (
|
||||
existing_instance["asset"] != asset_name
|
||||
or existing_instance["task"] != task_name
|
||||
):
|
||||
asset_doc = get_asset_by_name(project_name, asset_name)
|
||||
subset_name = self.get_subset_name(
|
||||
self.default_variant, task_name, asset_doc,
|
||||
project_name, host_name
|
||||
)
|
||||
existing_instance["asset"] = asset_name
|
||||
existing_instance["task"] = task_name
|
||||
existing_instance["subset"] = subset_name
|
||||
|
||||
def get_icon(self):
|
||||
return qtawesome.icon("fa.file-o", color="white")
|
||||
|
||||
def _imprint(self, comp, data):
|
||||
|
||||
# TODO: Should this keys persist or not? I'd prefer not
|
||||
# Do not persist the current context for the Workfile
|
||||
for key in ["variant", "subset", "asset", "task"]:
|
||||
data.pop(key, None)
|
||||
|
||||
# Flatten any potential nested dicts
|
||||
data = flatten_dict(data, separator=".")
|
||||
|
||||
# Prefix with data key openpype.workfile
|
||||
data = {f"{self.data_key}.{key}" for key, value in data.items()}
|
||||
comp.SetData(data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue