🐛 workfile instance changes are now persisted

This commit is contained in:
Ondřej Samohel 2022-10-24 18:11:06 +02:00
parent d5afbcd005
commit a8f1e95696
No known key found for this signature in database
GPG key ID: 02376E18990A97C6
2 changed files with 40 additions and 23 deletions

View file

@ -136,7 +136,7 @@ class HoudiniHost(HostBase, IWorkfileHost, ILoadHost, INewPublisher):
)
@staticmethod
def _create_context_node():
def create_context_node():
"""Helper for creating context holding node.
Returns:
@ -151,20 +151,20 @@ class HoudiniHost(HostBase, IWorkfileHost, ILoadHost, INewPublisher):
op_ctx.setCreatorState("OpenPype")
op_ctx.setComment("OpenPype node to hold context metadata")
op_ctx.setColor(hou.Color((0.081, 0.798, 0.810)))
op_ctx.hide(True)
# op_ctx.hide(True)
return op_ctx
def update_context_data(self, data, changes):
op_ctx = hou.node(CONTEXT_CONTAINER)
if not op_ctx:
op_ctx = self._create_context_node()
op_ctx = self.create_context_node()
lib.imprint(op_ctx, data)
def get_context_data(self):
op_ctx = hou.node(CONTEXT_CONTAINER)
if not op_ctx:
op_ctx = self._create_context_node()
op_ctx = self.create_context_node()
return lib.read(op_ctx)
def save_file(self, dst_path=None):

View file

@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
"""Creator plugin for creating workfiles."""
from openpype.hosts.houdini.api import plugin
from openpype.hosts.houdini.api.lib import read
from openpype.hosts.houdini.api.lib import read, imprint
from openpype.hosts.houdini.api.pipeline import CONTEXT_CONTAINER
from openpype.pipeline import CreatedInstance, AutoCreator
from openpype.pipeline.legacy_io import Session
from openpype.pipeline import legacy_io
from openpype.client import get_asset_by_name
import hou
class CreateWorkfile(plugin.HoudiniCreatorBase, AutoCreator):
@ -12,7 +14,7 @@ class CreateWorkfile(plugin.HoudiniCreatorBase, AutoCreator):
identifier = "io.openpype.creators.houdini.workfile"
label = "Workfile"
family = "workfile"
icon = "gears"
icon = "document"
default_variant = "Main"
@ -25,9 +27,9 @@ class CreateWorkfile(plugin.HoudiniCreatorBase, AutoCreator):
), None)
project_name = self.project_name
asset_name = Session["AVALON_ASSET"]
task_name = Session["AVALON_TASK"]
host_name = Session["AVALON_APP"]
asset_name = legacy_io.Session["AVALON_ASSET"]
task_name = legacy_io.Session["AVALON_TASK"]
host_name = legacy_io.Session["AVALON_APP"]
if current_instance is None:
asset_doc = get_asset_by_name(project_name, asset_name)
@ -44,17 +46,16 @@ class CreateWorkfile(plugin.HoudiniCreatorBase, AutoCreator):
variant, task_name, asset_doc,
project_name, host_name, current_instance)
)
new_instance = CreatedInstance(
self.log.info("Auto-creating workfile instance...")
current_instance = CreatedInstance(
self.family, subset_name, data, self
)
self._add_instance_to_context(new_instance)
# Update instance context if is not the same
self._add_instance_to_context(current_instance)
elif (
current_instance["asset"] != asset_name
or current_instance["task"] != task_name
):
# Update instance context if is not the same
asset_doc = get_asset_by_name(project_name, asset_name)
subset_name = self.get_subset_name(
variant, task_name, asset_doc, project_name, host_name
@ -63,14 +64,30 @@ class CreateWorkfile(plugin.HoudiniCreatorBase, AutoCreator):
current_instance["task"] = task_name
current_instance["subset"] = subset_name
# write workfile information to context container.
op_ctx = hou.node(CONTEXT_CONTAINER)
if not op_ctx:
op_ctx = self.create_context_node()
workfile_data = {"workfile": current_instance.data_to_store()}
imprint(op_ctx, workfile_data)
def collect_instances(self):
self.cache_instances(self.collection_shared_data)
for instance in self.collection_shared_data["houdini_cached_instances"].get(self.identifier, []): # noqa
created_instance = CreatedInstance.from_existing(
read(instance), self
)
self._add_instance_to_context(created_instance)
op_ctx = hou.node(CONTEXT_CONTAINER)
instance = read(op_ctx)
if not instance:
return
workfile = instance.get("workfile")
if not workfile:
return
created_instance = CreatedInstance.from_existing(
workfile, self
)
self._add_instance_to_context(created_instance)
def update_instances(self, update_list):
pass
op_ctx = hou.node(CONTEXT_CONTAINER)
for created_inst, _changes in update_list:
if created_inst["creator_identifier"] == self.identifier:
workfile_data = {"workfile": created_inst.data_to_store()}
imprint(op_ctx, workfile_data, update=True)