# Importing multiple files in blender import plugin

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.

0

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(
type=bpy.types.OperatorFileListElement,
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
print(filepath)


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

from bpy.props import (
BoolProperty,
CollectionProperty,
StringProperty,
)

• Thanks @Luther, most helpful. io_import_images_as_planes.py has a working example of this. – Ron Jensen Aug 7 at 15:24