I'm writing an import plugin for blender 2.8x and I'd like to make use of the multiple file selection feature. Unfortunately, I can't find any provision for this in 'ImportHelper' (the class I derive from) and web searches haven't yielded anything that seems to work and I can't seem to find anything in the documentation either.



It turns out there are several things you need to do to make this work, it's not yet covered in the documentation.

First of all, it helps to know what the base class 'ImportHelper' does when using it in an import script. On initialisation, the script calls 'context.window_manager.fileselect_add(self)' which adds several objects to your class. This string in the source code gave it away:

"The string properties 'filepath', 'filename', 'directory' and a 'files' " "collection are assigned when present in the operator"

The 'files' object is what we need but that's only present in if you also have the correct property present in your class, for example:

files: CollectionProperty(
            options={'HIDDEN', 'SKIP_SAVE'},

then, if that is present, you can access this in your class's 'execute' method to iterate through all the files in your selection:

for meshfile in self.files:
            filepath = meshfile.name

Also, remember to include the correct properties, I include these in my importer:

from bpy.props import (
| improve this answer | |
  • $\begingroup$ Thanks @Luther, most helpful. io_import_images_as_planes.py has a working example of this. $\endgroup$ – Ron Jensen Aug 7 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.