Skip to content

Instantly share code, notes, and snippets.

@zachlewis
Created November 29, 2021 16:31
Show Gist options
  • Save zachlewis/39a121d07025e2727527d0446b2b5da5 to your computer and use it in GitHub Desktop.
Save zachlewis/39a121d07025e2727527d0446b2b5da5 to your computer and use it in GitHub Desktop.
PyOpenColorIO format metadata method
import PyOpenColorIO as ocio
from typing import Union, List
def set_transform_metadata(
transform: ocio.Transform,
name: str = "",
id: str = "",
description: Union[str, List[str]] = "",
input_descriptor: str = "",
output_descriptor: str = "",
) -> ocio.Transform:
"""
Sets *PyOpenColorIO.Transform format metadata attributes.
"""
if not hasattr(transform, "getFormatMetadata"):
group_transform = ocio.GroupTransform([transform])
return set_transform_metadata(
group_transform,
name=name,
id=id,
description=description,
input_descriptor=input_descriptor,
output_descriptor=output_descriptor,
)
fmd = transform.getFormatMetadata()
if name:
fmd.setName(str(name))
if id:
fmd.setID(str(id))
if description:
if not isinstance(description, (list, tuple, slice)):
description = [description]
for i in description:
fmd.addChildElement(ocio.METADATA_DESCRIPTION, i)
if input_descriptor:
fmd.addChildElement(ocio.METADATA_INPUT_DESCRIPTOR, input_descriptor)
if output_descriptor:
fmd.addChildElement(ocio.METADATA_OUTPUT_DESCRIPTOR, output_descriptor)
return transform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment