Skip to content

Instantly share code, notes, and snippets.

Created November 8, 2023 19:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save BigRoy/c4d2d04a799513e60a36cb2d3e91d04b to your computer and use it in GitHub Desktop.
OpenPype Extractor Mixin
class ExtractorMixin:
"""OpenPype Extractor helper methods"""
def add_representation(self, instance, name,
files, staging_dir, ext=None,
"""Add a representation to publish and integrate.
A representation must exist of either a single file or a
single file sequence. It can *not* contain multiple files.
For the integration to succeed the instance must provide the context
for asset, frame range, etc. even though the representation can
override some parts of it.
instance (pyblish.api.Instance): Publish instance
name (str): The representation name
ext (Optional[str]): Explicit extension for the output
output_name (Optional[str]): Output name suffix for the
destination file to ensure the file is unique if
multiple representations share the same extension.
dict: Representation data for integration.
if ext is None:
# TODO: Use filename
ext = name
representation = {
"name": name,
"ext": ext,
"stagingDir": staging_dir,
"files": files
if output_name:
representation["outputName"] = output_name
if frame_start is not None:
representation["frameStart"] = int(frame_start)
if frame_end is not None:
representation["frameEnd"] = int(frame_end)
if colorspace is not False:
colorspace=colorspace)"representations", []).append(
return representation
def add_transfer(self, instance, source, destination):
"""Add a file transfer to the integration
This can be used e.g. for resource files to a publish that
do not need to be a representation of its own and avoids
any publish template renaming of the files at destination.
instance (pyblish.api.Instance): Publish instance
source (str): Full path to source file
destination (str): Full or relative path to destination
If destination is relative path, then it will
be transfered relative to instance's `publishDir`
tuple: The registered transfer
if not os.path.isabs(destination):
destination = os.path.join(["publishDir"], destination)
transfer = src, destination"transfers", []).append(transfer)
return transfer
Copy link

BigRoy commented Nov 8, 2023

Usage example:

class Extractor(pyblish.api.InstancePlugin, ExtractorMixin):
    families = ["usd"]
    label = "Extractor"
    order = pyblish.api.ExtractorOrder

    def process(self, instance):
        staging_dir = self.staging_dir()
        files = export()
        self.add_representation(instance, "usd", files, staging_dir)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment