← All ideas
  • Published 2 Aug 2023

Folder Select when writing addons

I was working on an addon for exporting multiple objects to separate files (in this particular case FBX), I got to the point where the actual save location needed to be selected, but the only option for a 'save dialog' is a file one, while most of the 'features' in Blender only require to select files, not having a folder select version of the same limits the possibilities for writing addons (like batch import/exporters)

0%

Development Status: Open

Upvote 0 Downvote 0
joel9
2 Aug 2023

1 Comment

Lauloque

We do have it.

In Blender, the UI works in tandem with the kind of data you use it for. You create a property of some sort, with a specific subtype, and the UI you make to access that property will adapt for that specific type and subtype of data.

In your case, to get a folder browser, you need to make a stringProperty of the DIR_PATH subtype.

Example:

import bpy

class SimplePanel(bpy.types.Panel):
    bl_label = "Folder Input"
    bl_idname = "OBJECT_PT_folder_input"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Item"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        # UI CREATION
        layout.prop(scene, "my_folder", text="Select Folder")

def register():
    # STRING PROPERTY DEFINITION
    bpy.types.Scene.my_folder = bpy.props.StringProperty(subtype="DIR_PATH")
    bpy.utils.register_class(SimplePanel)

def unregister():
    bpy.utils.unregister_class(SimplePanel)
    del bpy.types.Scene.my_folder

if __name__ == "__main__":
    register()

More about it:

2