
However, I want to add an additional feature to the class. I’m using the ExportHelper class to export 3D objects. There’s also an ExportHelper class that includes some utilities to check for existing files and setting a default untitled filename in the browser.ĭid I miss something? Let me know in the comments! Print('Some Boolean:', self.some_boolean)īpy.utils.register_class(OT_TestOpenFilebrowser)īpy.utils.unregister_class(OT_TestOpenFilebrowser)īpy._filebrowser('INVOKE_DEFAULT') You can take care of that with good old splitext().įilename, extension = os.path.splitext(self.filepath)Īnd what about adding settings to the filebrowser screen? All you have to do is add properties to the operator as usual and they will show up in the browser.ĭescription='Do a thing with the file you\'ve selected',įrom bpy.props import StringProperty, BoolPropertyĬlass OT_TestOpenFilebrowser(Operator, ImportHelper): You might want to reject a file or do something different depending on the extension you receive. Note that strings longer that 255 could be cut (since that’s the internal buffer size).ĭefault='*.jpg *.jpeg *.png *.tif *.tiff *.bmp',Īlso keep in mind that users can disable filtering in the UI and select any kind of file. Each extension is written in wildcard style and is separated by a semi-colon. This is a StringProperty with the list of extensions we want to show. To filter the types of files shown to the user we have to add a filter_glob property to our class. Note that this is a regular StringProperty inside ImportHelper that we inherited when we subclassed it. Our new operator already has an invoke() function that calls the filebrowser and when a user selects a file, it stores the file’s path in self.filepath. """Do something with the selected file(s)."""

Now we can go ahead and create the operator: class OT_TestOpenFilebrowser(Operator, ImportHelper): Let’s start by importing both ImportHelper and Operator.įrom bpy_extras.io_utils import ImportHelper To use it all we have to do is extend it in our operator.

It includes an invoke() function that calls the filebrowser and a few helper functions used in Blender’s importer addons. Importhelper is a mix-in class found in the bpy_extras submodule.

Luckily Blender provides a handy class that does almost everything for us. Sure, you could just give users a simple string input and let them copy/paste into it but how much cooler would it be to let them pick a file from the filebrowser?

Every now and then an addon requires that the user selects a specific file or path.
