The topic of being able to archive soft-imported clips used in a timeline, batch, whatever in the original format and not duplicated has come up many times. Basically a way to “collect files”. I thought it’d be interesting to start working on a script to do this, or at least attempt to.
That said, I’ve run into a stumbling block: How to drill down into an unknown level of sub-folders until you find either a sequence, clip or batchgroup? If this was on a normal filesystem you could easily use os.walk and let it do it’s thing but, as far as I can tell, there isn’t a way to do that within the Flame.
I feel like there’s some clever way to write some sort of loop that can continue to call itself and keep running again when a new folder is found within the current folder.
Some simple code I’ve been testing with:
for libraries in flame.project.current_project.current_workspace.libraries:
print ("- ", libraries.name)
for folder in libraries.folders:
print (" +-- ", folder.name)
for i in range(len(folder.folders)):
print (" +-- ", folder.folders[i].name)
for x in range(len(folder.folders[i].folders)):
print (" +-- ", folder.folders[i].folders[x].name)
if len(selection.folders) == 0:
Does anyone have any ideas or suggestions of what else to look at? My python skills are pretty “throw a dart at the board” style so when it comes to more complex structures and whatnot I’m pretty lost.
Any help would be greatly appreciated, thanks.
Recursion is your friend!
By calling the function from itself again you can traverse through an unknown level of subfolders.
Here is a little example to build a list of all clips. I’ve modified some names slightly to stick to some Autodesk terminology (e.g. clips instead of entries etc.) to make things more understandable. Hope this helps.
clips = 
"""recursive search for entries"""
for folder in current_folder:
for clip in folder.clips:
"""function that returns all clips as a list"""
clips = 
for library in flame.project.current_project.current_workspace.libraries:
"""check if the given folder has any subfolders"""
if len(folder.folders) == 0:
This could be improved by running set on the list at the end or implementing another mechanism to avoid duplicate entries in the list.
Oh man, so simple! Love it. I didn’t realize you could call a function within itself…
Thank you so much @claussteinmassl !
Since we’re here…do you know if it’s possible to get the sequence range from a file path? Currently I can only seem to get
collected_clips[i].versions.tracks.segments.file_path to return the file path of the first file.
I.e. that will currently return
somefile_0000.exr and not
somefile_[0000-0120].exr which is what .mio files hold as well as what’s shown in the media panel under clip information.
I don’t know of a direct implementation. Not in Flame and not in Python in general. However there are projects like this, which can be a great starting point if you don’t want to reinvent the wheel:
Knowing the file path to the first frame, you could parse the directory to get the entire sequence.
Cool, I didn’t know this one, thanks @claussteinmassl
@ kyleobley you can also have a look at the clique module, specifically for image sequences :
Just used this for finding all sequences. Thanks a lot @claussteinmassl !!!