ImportHelper select multiple files

Can you access which files you have selected in file browser using ImportHelper?
filepath return only last one selected.

I mean in something like that:

class ImportSomeData(Operator, ImportHelper):
    bl_idname = "import_test.some_data" 
    bl_label = "Import Some Data"

    def execute(self, context):
        return read_some_data(context, self.filepath)


def read_some_data(context, filepath):

    #I want to know what i selected there


You can store them in a collection property:


class ImportSomeData(Operator, ImportHelper):
    bl_idname = "import_test.some_data" 
    bl_label = "Import Some Data"

    files = CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)

    def execute(self, context):
        for filepath in files:
            return read_some_data(context, filepath)


def read_some_data(context, filepath):

    #I want to know what i selected there

Thank you!

I used bpy.types.PropertyGroup with sucess, is there a benefit in using bpy.types.OperatorFileListElement instead?

I don’t know, I just never learned any other way to do it.

Hi There,
I’m a total beginner and wasted hours to achieve this, but can’t :frowning: I’ve tried chatGPT, BingAI, read google but for me it never gives more then one file path back. I want load multiple jpg-s and tif-s with filebrowser.

Please HELP me!!
My code:

Open Images Operator létrehozása

class OBJECT_OT_OpenImagesOperator(bpy.types.Operator, ImportHelper):
bl_idname = “object.open_images_operator”
bl_label = “Open Images”
bl_options = {‘REGISTER’, ‘UNDO’}
filter_glob: bpy.props.StringProperty(default=“.tif;.jpg”, options={‘HIDDEN’})

def execute(self, context):
    openfiles = self.filepath.split(';')        
             
    for file_path in openfiles:
        file_path = bpy.path.abspath(file_path)          
        print(file_path)

    return {'FINISHED'}

and at the end:

def register():
for cls in classes:
bpy.utils.register_class(cls)

bpy.types.Scene.openfiles = bpy.props.CollectionProperty(name='File paths', type=bpy.types.OperatorFileListElement)           

if name == “main”:
register()

What’s wrong?
Can somebody asap give me an EXACT EXAMPLE (a copy and paste code from beginning to end) where

  • there is a button, which i press and filebrowser comes up
  • it shows only jpg-s and tif-s
  • i select MULTIPLE FILES
  • then blender loads them all!

Thank you!

For multiple files you want to use self.files instead of self.filepath.

Add this in the operator definition

    files: CollectionProperty(
        type=OperatorFileListElement,
        options={"HIDDEN", "SKIP_SAVE"},
    )

and in execute

filepaths = [self.directory + f.name for f in self.files]

See https://docs.blender.org/api/current/bpy.types.OperatorFileListElement.html

:heart: Thank You