1
$\begingroup$

I'd like to use Blender to visualize several things that I have in a folder. I am visualizing a dataset which might contain a pointcloud, a 3D model, among others. I'd like to be able to select the dataset folder and not an individual file or a set of files. In the operator_file_import.py file there seems to be a filter_glob property which might be the solution, but it's not clear for me if there is pattern to match folders only. Is this actually possible?

From the scripting template

class ImportSomeData(Operator, ImportHelper):
    """This appears in the tooltip of the operator and in the generated docs"""
    bl_idname = "import_test.some_data"  # important since its how bpy.ops.import_test.some_data is constructed
    bl_label = "Import Some Data"

    # ImportHelper mixin class uses this
    filename_ext = ".txt"

    # ---> IS THERE A FILTER TO SELECT FOLDERS?
    filter_glob: StringProperty(
        default="*.txt",
        options={'HIDDEN'},
        maxlen=255,  # Max internal buffer length, longer would be clamped.
    )

    # List of operator properties, the attributes will be assigned
    # to the class instance from the operator settings before calling.
    use_setting: BoolProperty(
        name="Example Boolean",
        description="Example Tooltip",
        default=True,
    )

    type: EnumProperty(
        name="Example Enum",
        description="Choose between two items",
        items=(
            ('OPT_A', "First Option", "Description one"),
            ('OPT_B', "Second Option", "Description two"),
        ),
        default='OPT_A',
    )

    def execute(self, context):
        return read_some_data(context, self.filepath, self.use_setting)
```
$\endgroup$

1 Answer 1

3
$\begingroup$

Here's a short snippet of how you can print out the currently opened directory in the console. You have to use the directory attribute and set the filter_glob to "" to filter only directories.

import bpy

from bpy_extras.io_utils import ImportHelper
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import Operator


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

    directory: StringProperty()

    filter_glob: StringProperty(
        default="",
        options={'HIDDEN'},
        maxlen=255,  # Max internal buffer length, longer would be clamped.
    )
    
    def execute(self, context):
        print(self.directory)
        return {"FINISHED"}

def menu_func_import(self, context):
    self.layout.operator(ImportSomeData.bl_idname, text="Text Import Operator")

bpy.utils.register_class(ImportSomeData)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .