Skip to content

Instantly share code, notes, and snippets.

@BigRoy
Last active April 18, 2023 13:16
Show Gist options
  • Save BigRoy/406605f6e295774c401b7d2f57a26b6e to your computer and use it in GitHub Desktop.
Save BigRoy/406605f6e295774c401b7d2f57a26b6e to your computer and use it in GitHub Desktop.
OpenRV Python find annotated frames including those made in sequence group views
import rv
def get_source_frame(frame, root, source):
source_types = {"RVImageSource", "RVFileSource"}
# Find the frame for `source` at `frame` when viewing `root`
for info in rv.commands.metaEvaluate(frame, root):
if info["node"] == source:
return info["frame"]
def get_annotations(source):
"""Get annotation for source including those made in RVSequenceGroup
It would make more sense for this function to also return the group
it found the frame in so that it could be used to retrieve the
annotation correctly, for example to export the annotation.
Also note that if 'Annotation > Configure > Draw on source if possible'
would be enabled then the logic to look into sequence groups would be
redundant since it'd draw into the source group then anyway.
"""
group = rv.commands.nodeGroup(source)
inputs, outputs = rv.commands.nodeConnections(group)
# We assume that outputs are all viewable groups
# in which each could potentially have annotations
# over the source
annotated_frames = set()
for output in outputs:
# We ignore stack and layout groups since it's complex to detect what
# part of the annotation ended up where on the sources.
if rv.commands.nodeType(output) != "RVSequenceGroup":
continue
with lib.active_view(output):
frames = list(sorted(set(rv.extra_commands.findAnnotatedFrames())))
for frame in frames:
frame = get_source_frame(frame, root=output, source=source)
if frame is None:
# Source is not visible at that frame
continue
source_frame = rv.extra_commands.sourceFrame(frame)
annotated_frames.add(source_frame)
with lib.active_view(group):
frames = rv.extra_commands.findAnnotatedFrames()
annotated_frames.update(frames)
return list(sorted(annotated_frames))
for source in rv.commands.sourcesAtFrame(rv.commands.frame()):
annotations = get_annotations(source)
print(source, annotations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment