Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from BigRoy/fusion-new-publisher
Browse files Browse the repository at this point in the history
Fusion: New Publisher tweaks to PR
  • Loading branch information
EmberLightVFX authored Mar 6, 2023
2 parents ef6cb62 + 9a25af3 commit ddcbca0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 80 deletions.
6 changes: 4 additions & 2 deletions openpype/hosts/fusion/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ def get_containers(self):
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):
Expand Down
24 changes: 14 additions & 10 deletions openpype/hosts/fusion/plugins/create/create_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
Creator,
CreatedInstance
)
from openpype.client import get_asset_by_name


class CreateSaver(Creator):
Expand Down Expand Up @@ -87,15 +88,10 @@ def get_icon(self):
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)

Expand Down Expand Up @@ -150,14 +146,22 @@ def _collect_unmanaged_saver(self, tool):
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,
Expand Down
110 changes: 42 additions & 68 deletions openpype/hosts/fusion/plugins/create/create_workfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@
)


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"
Expand All @@ -33,7 +22,7 @@ class FusionWorkfileCreator(AutoCreator):

create_allow_context_change = False

data_key = "openpype.workfile"
data_key = "openpype_workfile"

def collect_instances(self):

Expand All @@ -53,21 +42,17 @@ def collect_instances(self):
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):

Expand All @@ -76,61 +61,50 @@ def create(self, options=None):
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
))

instance = CreatedInstance(
family=self.family,
subset_name=subset_name,
data=data,
creator=self
)
instance.transient_data["comp"] = comp
self._add_instance_to_context(instance)

self._imprint(comp, 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
))

new_instance = CreatedInstance(
self.family, subset_name, data, self
)
self._add_instance_to_context(new_instance)

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)

0 comments on commit ddcbca0

Please sign in to comment.