Created
February 17, 2017 14:29
-
-
Save p2or/8fcdd2d01540798d937cf9ac2d863fb9 to your computer and use it in GitHub Desktop.
List Files of loaded Image Sequence #Blender #BSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for http://blender.stackexchange.com/q/73858/3710 | |
import bpy | |
import os | |
def image_sequence_resolve(operator, context): | |
filepath = context.space_data.clip.filepath | |
filepath_full = bpy.path.abspath(filepath) | |
basedir, filename = os.path.split(filepath_full) | |
filename_noext, ext = os.path.splitext(filename) | |
from string import digits | |
if isinstance(filepath, bytes): | |
digits = digits.encode() | |
filename_nodigits = filename_noext.rstrip(digits) | |
if len(filename_nodigits) == len(filename_noext): | |
# input isn't from a sequence | |
return [] | |
files = os.listdir(basedir) | |
return [ | |
os.path.join(basedir, f) | |
for f in files | |
if f.startswith(filename_nodigits) and | |
f.endswith(ext) and | |
f[len(filename_nodigits):-len(ext) if ext else -1].isdigit()] | |
class CLIP_OT_image_sequence(bpy.types.Operator): | |
bl_idname="clip.image_sequence" | |
bl_label="List Files of Image Sequence" | |
@classmethod | |
def poll(cls, context): | |
spc = context.space_data | |
return (spc.type == 'CLIP_EDITOR') and spc.clip | |
def execute(self, context): | |
spc = context.space_data | |
if spc.clip.source == 'SEQUENCE': | |
print(image_sequence_resolve(self, context)) | |
self.report({"INFO"}, "Image Sequence: {}".format(spc.clip.name)) | |
else: | |
self.report({"INFO"}, "Not a sequence") | |
return {'FINISHED'} | |
def register(): | |
bpy.utils.register_class(CLIP_OT_image_sequence) | |
def unregister(): | |
bpy.utils.unregister_class(CLIP_OT_image_sequence) | |
if __name__ == "__main__": | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment