5
$\begingroup$

When Blender references an image sequence, the image.filepath only ever references one image at a time.

However for renderfarms and copying projects between systems, you may want to get all the images associated with in image sequence.

How would you go about getting all the images in an image sequence for a Blender Image or Movie-Clip?

$\endgroup$
1
  • $\begingroup$ posted as an example since I needed to solve myself. $\endgroup$
    – ideasman42
    Commented Dec 18, 2014 at 17:00

2 Answers 2

5
$\begingroup$

This function returns all the images which share the same prefix, suffix (and have a number suffix), eg: /path/to/my_image_0001.png

def image_sequence_resolve_all(filepath):
    import os

    basedir, filename = os.path.split(filepath)
    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 []

    return [
        f.path
        for f in os.scandir(basedir)
        if f.is_file() and
           f.name.startswith(filename_nodigits) and
           f.name.endswith(ext) and
           f.name[len(filename_nodigits):-len(ext) if ext else -1].isdigit()
    ]


# example use
print(resolve_image_sequence("/path/to/my_image_0001.png"))
>> ["/path/to/my_image_0001.png",
    "/path/to/my_image_0002.png",
    "/path/to/my_image_0003.png",
    ]
$\endgroup$
1
$\begingroup$

You can use https://pypi.python.org/pypi/Clique/1.5.0 Clique module. It was created for tasks like that.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .