How to add multiple media representations in Python for RV?

How can we add multiple media representations via Python in RV please? :pray:

The docs state that addSourceMediaRep or an overload for addSourcesVerbose could be used

The overload of addSourcesVerbose directly taken from the example docs

rv.commands.addSourcesVerbose([“image_sequence.195-215#.jpg”, “+mediaRepName”, “Frames”, “+mediaRepSource”, “last”])

leads to this error

ERROR: Traceback (most recent call last):
ERROR: File “C:\Program Files\Autodesk\RV-2024.1.0\src\sgtk\baked\plugin\bundle_cache\app_store\tk-multi-pythonconsole\v1.4.0\python\app\”, line 246, in execute
ERROR: exec(python_code, self._locals, self._locals)
ERROR: File “python input”, line 8, in
ERROR: TypeError: Bad argument (0) to function commands.addSourcesVerbose: expecting dynamic array

Using [] instead doesn’t lead to an error:

rv.commands.addSourcesVerbose([[“image_sequence.195-215#.jpg”, “+mediaRepName”, “Frames”, “+mediaRepSource”, “last”]])

but leads to the same result as using

rv.commands.addSourceMediaRep(“last”, “Frames”, [“image_sequence.195-215#.jpg”])

ie that 2 separate sources are created (see attached screenshot)

The result we expect instead is that there is one source with multiple represenations that can be switched between.

Here example code to reproduce the issue in RV Python Console

import rv

src1 = ""
src2 = ""

src1_node = rv.commands.addSourceVerbose([src1])
rv.commands.addSourceMediaRep("last", "Streaming", [src2])

# rv.commands.addSourcesVerbose([[src2, "+mediaRepName", "Streaming", "+mediaRepSource", "last"]])

# rv.commands.addSourcesVerbose(["image_sequence.195-215#.jpg", "+mediaRepName", "Frames", "+mediaRepSource", "last"])
# rv.commands.addSourcesVerbose([["image_sequence.195-215#.jpg", "+mediaRepName", "Frames", "+mediaRepSource", "last"]])
# rv.commands.addSourceMediaRep("last", "Frames", ["image_sequence.195-215#.jpg"])

(the example uses two streaming sources but the results were the same with streaming/frames etc and it makes for an easier example to be able to use URLs)

Thanks :pray:

Hi, I think there are some misconseptions about how the SourceMediaReps work.

It basically (to my understanding) just creates a switch node for your convenience and adds all sourceMediaReps to this switch node. So you will see both sources in your session, but they are both represented by your switch_node.

Just adding a media rep to a source without a MediaRepName also doesn’t work very well, because the switch node doesn’t give you the option to switch to the other reps then (this should work imo so maybe some overlooked thing from rv side)

Anyways, just giving your first node a mediarepname should make it work (almost) like you would expect :slight_smile:

import rv

src1 = ""
src2 = ""

rv.commands.addSourcesVerbose([[src1, "+mediaRepName", "Small"]])
rv.commands.addSourceMediaRep("last", "Large", [src2])

With this you can then switch between the two.



  • The “Streaming” you had before is just a name for the mediaReps, so you can put any name you want there
  • Until you first switch to the other rep, the source does not get loaded in to the session, so an empty source_group node will appear in your session manager

Hope that helps!
Cheers, Mirco

1 Like

thank you this works great.

just out of curiosity how did you find out that this needs to be done since its not in the documentation as much as i can see?

I tested the code you provided and tried setting the second mediaRep. That worked and I could switch to the other(original) one but not back. So I figured it’s because this one doesn’t have a mediaRepName and rv checks for that.

I guess a combination of testing and experience with how RV works (or doesn’t) sometimes :smiley:

I started a cookbook for RV for those that come behind us :slight_smile: and added some of your solutions :wink:


The documentation is definitely misleading ! Sorry about that.
We are going to fix it today.
Thanks to both of you !

1 Like

Thank you and where you can please add full examples like this one

It’s sooooo much easier and fun to program with RV then as it takes the guess work out of it.