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

Commit

Permalink
Draft refactor workfile to new publisher - show workfile in UI
Browse files Browse the repository at this point in the history
- Storing any settings/data of the workfile is not implemented yet, as such any changes you make on the Workfile instance will not yet persist on reset or reopening the publisher. (So basically similar behavior to old publisher?)
  • Loading branch information
BigRoy committed Oct 7, 2023
1 parent 661ffb0 commit d3d4723
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 58 deletions.
72 changes: 72 additions & 0 deletions openpype/hosts/resolve/plugins/create/create_workfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
"""Creator plugin for creating workfiles."""
from openpype.pipeline import CreatedInstance, AutoCreator
from openpype.client import get_asset_by_name


class CreateWorkfile(AutoCreator):
"""Workfile auto-creator."""
identifier = "io.openpype.creators.resolve.workfile"
label = "Workfile"
family = "workfile"
icon = "fa5.file"

default_variant = "Main"

def create(self):

variant = self.default_variant
current_instance = next(
(
instance for instance in self.create_context.instances
if instance.creator_identifier == self.identifier
), None)

project_name = self.project_name
asset_name = self.create_context.get_current_asset_name()
task_name = self.create_context.get_current_task_name()
host_name = self.create_context.host_name

if current_instance is None:
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
)
data = {
"asset": asset_name,
"task": task_name,
"variant": variant,
}
data.update(
self.get_dynamic_data(
variant, task_name, asset_doc,
project_name, host_name, current_instance)
)
self.log.info("Auto-creating workfile instance...")
current_instance = CreatedInstance(
self.family, subset_name, data, self
)
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
)
current_instance["asset"] = asset_name
current_instance["task"] = task_name
current_instance["subset"] = subset_name

def collect_instances(self):
# TODO: Implement
pass

def update_instances(self, update_list):
# TODO: Implement
# This needs to be implemented to allow persisting any instance
# data on resets. We'll need to decicde where to store workfile
# instance data reliably. Likely metadata on the *current project*?
pass
30 changes: 30 additions & 0 deletions openpype/hosts/resolve/plugins/publish/collect_current_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pyblish.api

from openpype.hosts.resolve import api as rapi
from openpype.hosts.resolve.otio import davinci_export


class CollectResolveProject(pyblish.api.ContextPlugin):
"""Collect the current Resolve project and current timeline data"""

label = "Collect Project and Current Timeline"
order = pyblish.api.CollectorOrder - 0.499

def process(self, context):
project = rapi.get_current_project()
fps = project.GetSetting("timelineFrameRate")
video_tracks = rapi.get_video_track_names()

# adding otio timeline to context
otio_timeline = davinci_export.create_otio_timeline(project)

# update context with main project attributes
context.data.update({
# project
"activeProject": project,
"currentFile": project.GetName(),
# timeline
"otioTimeline": otio_timeline,
"videoTracks": video_tracks,
"fps": fps,
})
15 changes: 15 additions & 0 deletions openpype/hosts/resolve/plugins/publish/collect_workfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pyblish.api


class CollectWorkfile(pyblish.api.InstancePlugin):
"""Collect the current working file into context"""

families = ["workfile"]
label = "Collect Workfile"
order = pyblish.api.CollectorOrder - 0.49

def process(self, instance):
# Backwards compatibility - workfile instances previously had 'item'
# in Resolve.
# TODO: Remove this if it is not needed
instance.data["item"] = instance.context.data["activeProject"]
17 changes: 9 additions & 8 deletions openpype/hosts/resolve/plugins/publish/extract_workfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def process(self, instance):
project = instance.context.data["activeProject"]
staging_dir = self.staging_dir(instance)

resolve_workfile_ext = ".drp"
drp_file_name = name + resolve_workfile_ext
ext = ".drp"
drp_file_name = name + ext
drp_file_path = os.path.normpath(
os.path.join(staging_dir, drp_file_name))

Expand All @@ -35,17 +35,18 @@ def process(self, instance):

# create drp workfile representation
representation_drp = {
'name': resolve_workfile_ext[1:],
'ext': resolve_workfile_ext[1:],
'name': ext.lstrip("."),
'ext': ext.lstrip("."),
'files': drp_file_name,
"stagingDir": staging_dir,
}

instance.data["representations"].append(representation_drp)
representations = instance.data.setdefault("representations", [])
representations.append(representation_drp)

# add sourcePath attribute to instance
if not instance.data.get("sourcePath"):
instance.data["sourcePath"] = drp_file_path

self.log.info("Added Resolve file representation: {}".format(
representation_drp))
self.log.debug(
"Added Resolve file representation: {}".format(representation_drp)
)
50 changes: 0 additions & 50 deletions openpype/hosts/resolve/plugins/publish/precollect_workfile.py

This file was deleted.

0 comments on commit d3d4723

Please sign in to comment.