flame: add function to maintain object duplication

This commit is contained in:
Jakub Jezek 2022-01-14 11:53:35 +01:00
parent 4a230b710e
commit cc20a22e3a
No known key found for this signature in database
GPG key ID: D8548FBF690B100A
2 changed files with 26 additions and 1 deletions

View file

@ -27,7 +27,8 @@ from .lib import (
get_clips_in_reels,
get_reformated_path,
get_frame_from_path,
get_padding_from_path
get_padding_from_path,
maintained_object_duplication
)
from .utils import (
setup,
@ -93,6 +94,7 @@ __all__ = [
"get_reformated_path",
"get_frame_from_path",
"get_padding_from_path",
"maintained_object_duplication",
# pipeline
"install",

View file

@ -675,3 +675,26 @@ def get_frame_from_path(path):
return found.pop()
else:
return None
@contextlib.contextmanager
def maintained_object_duplication(item):
"""Maintain input item duplication
Attributes:
item (any flame.PyObject): python api object
Yield:
duplicate input PyObject type
"""
import flame
# Duplicate the clip to avoid modifying the original clip
duplicate = flame.duplicate(item)
try:
# do the operation on selected segments
yield duplicate
finally:
# delete the item at the end
flame.delete(duplicate)