Export annotations via pythonfunction

how do I export annotations via python as a function with given filepath.
In my world I imagine something like
exportAnnotatedFrames(filepath+filename+"%04d.jpg")

I managed to import this function form rvui.mu but then i get the gui popupwindow to enter the filepath and name.

for any hintes I am grateful

Hi Phil,

If you check out plugins/Mu/rvui.mu’s exportAnnotatedFrames you’ll see that it is effectively doing the following pseudocode:

Save the currently marked frames as a list
Clear the marked frames
Mark the annotated frames
Export the Marked Frames
Clear the marked frames
Restore the saved marked frames.

exportMarked() is where the file system dialog is called.

You can effectively replace the whole sequence of events in Python if you wanted to with something kinda like this (though, admittedly, without feeding the external process back into the State object, it won’t show the built in progress dialog

import rv
import pymu


priorMarked = rv.commands.markedFrames()
annotatedFrames = rv.extra_commands.findAnnotatedFrames()

# Use set differences to figure out what frames we need to mark and unmark
toAdd = list(set(annotatedFrames) - set(priorMarked))
toSub = list(set(priorMarked)-set(annotatedFrames))

# Generalize this into a function so you can reverse it after export.
for f in toSub:
    rv.commands.markFrame(f, False)
for f in toAdd:
    rv.commands.markFrame(f, True)
rv.commands.redraw()

# Do your path substitution here
rv.runtime.eval("""
require runtime;
use rvtypes;
{
runtime.load_module("export_utils");
let Fname = runtime.intern_name("export_utils.exportMarkedFrames");
(ExternalProcess;string,string) F = runtime.lookup_function(Fname);
 F("D:/test.%04d.jpg", "default");
}
""", [])

If you want to get really fancy with parallelism, check out how the h264 exporter example plugin works between Python and Mu with signal passing.

2 Likes

Hi Michael,
thanks so much for your help and the time invested !!!
it works quite well. :smiley:

May I ask you a last question?

As soon I replace “D:/test.%04d.jpg” with a variable called “exportFilename” containing the same string I get an error:

def exportAnnos(event):

.
.
rv.commands.redraw()

        exportFilename = "D:/test.%04d.jpg" 

        # Do your path substitution here
        rv.runtime.eval("""
        require runtime;
        use rvtypes;
        {
        runtime.load_module("export_utils");
        let Fname = runtime.intern_name("export_utils.exportMarkedFrames");
        (ExternalProcess;string,string) F = runtime.lookup_function(Fname);
         F(exportFilename , "default");
        }
        """, [ ])

ERROR: Exception thrown while calling runtime.eval
Traceback (most recent call last):
File “c:/Program Files/Shotgun/RV 6.2.6/scripts/rv/rvrc.py”, line 131, in exportAnnos
“”", )

line 131 is “”", )

when you set your filename, are you using string replacement?

PS: Yeesh, that’s an old version of RV ;).

Ok, thank you very much Michael !
There is nothing I can do, cause the company uses the old rv .
But I think your code will help others, it is a thing most companys will need to do and if they don’t have already it wil help.

All the best:
Philipp

1 Like

Hey

I tried this out to export annotated frames.
Unfortunately, I get this error when executing the code.

rv.runtime(“”"require runtime;)
ValueError: unexpected ‘{’ in the field name

What am I doing wrong, or is there a work around?

Thanks
Braden

Make sure you don’t have unicode quotes in there in case it was a paste error.

image

Also, presumably that was the code inside the quotes, right?

I was also using curly braces for formating in my export file name. Obviously with the other curly braces, the format wasn’t working correctly.

I also discovered export file name requires forward slashes, or it doesn’t write anything out

Is there a way to name the files based on the source image the annotations were drawn on? So if there are 3 shots in a session each with their own annotations, can I export the annotations and get shot1.%04d.jpg, shot2.%04d.jpg, shot3.%04d.jpg?