How to get the current file name via python?

Hi all,

I feel incredibly stupid asking this but I just can’t find the info anywhere, and RV’s API still does my head in every time I try to use it.
I am simply trying to get the current file path of a clip loaded in RV via python.
I used this (probably because somebody told me to in the past):

frame = commands.frameStart()
sources = commands.sourcesAtFrame(frame)
fileNames = commands.getStringProperty("" % sources[0], 0, 1000)

But that returns a sequence listing like this:
(u’LUM3_00054_010_V002.1001-1241@@@@@@.exr’, 1001, 1241, 1, 25.0, False, True)

I just need the actual file name/path instead.



Hey Frank!

@alexaz and I went over a couple options; it kinda comes down to what you want to do with it.

If you want the fast and easy approach, you can just query the source and ask for the media info. Something like this:

from rv import commands
frame = commands.frameStart()
sources = commands.sourcesAtFrame(frame)
metadata =  commands.sourceMediaInfo(sources[0])

# In the metadata, one key is 'file' which has your full path including sequence name.
file = metadata.get("file") 

I originally misinterpreted your request, but I think the answer has value. If you are looking for the specific file that you are reading from your sequence, you can do something along the lines of this:

import rv

# The difference here is that we traverse the graph to find not only the source, but also the source frame number.
info = rv.extra_commands.sourceMetaInfoAtFrame(rv.commands.frame())
metadata =  rv.commands.sourceMediaInfo(info['node'])
filename = metadata.get("file")
sourceFrame = info['frame']

# Note: this only works how we want it to for file sequences, error check to make sure you are dealing in file sequencese, as well as protecting yourself against missing framees.
files = rv.commands.existingFilesInSequence(filename)
frames = rv.commands.existingFramesInSequence(filename)

# Assmeble the files and frame numbers in something we can index into.
framesToFiles = dict(zip(frames, files))

# The result can be found here:

Hopefully those approaches find value in what you are trying to achieve.



Awesome, thanks, the first solution is all I need, thanks!