diff --git a/src/blenderbim/blenderbim/bim/module/fm/operator.py b/src/blenderbim/blenderbim/bim/module/fm/operator.py index 813ceae37a..77dd0ac72d 100644 --- a/src/blenderbim/blenderbim/bim/module/fm/operator.py +++ b/src/blenderbim/blenderbim/bim/module/fm/operator.py @@ -24,32 +24,21 @@ import logging import tempfile import ifcopenshell import blenderbim.tool as tool +from blenderbim.bim.operator import MultipleFileSelector -class SelectFMIfcFile(bpy.types.Operator): +class SelectFMIfcFile(MultipleFileSelector): bl_idname = "bim.select_fm_ifc_file" bl_label = "Select FM IFC File" - bl_options = {"REGISTER", "UNDO"} filename_ext = ".ifc" filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"}) - filepath: bpy.props.StringProperty(subtype="FILE_PATH") - files: bpy.props.CollectionProperty(name="File Path", type=bpy.types.OperatorFileListElement) def execute(self, context): props = context.scene.BIMFMProperties - props.ifc_files.clear() - dirname = os.path.dirname(self.filepath) - for f in self.files: - new = props.ifc_files.add() - new.name = os.path.join(dirname, f.name) - props.ifc_file = self.filepath + + self.update_props(props, "ifc_file", props.ifc_files) return {"FINISHED"} - def invoke(self, context, event): - context.window_manager.fileselect_add(self) - return {"RUNNING_MODAL"} - - class ExecuteIfcFM(bpy.types.Operator): bl_idname = "bim.execute_ifcfm" bl_label = "Execute IfcFM" diff --git a/src/blenderbim/blenderbim/bim/operator.py b/src/blenderbim/blenderbim/bim/operator.py index ccb5c58666..e68f818176 100644 --- a/src/blenderbim/blenderbim/bim/operator.py +++ b/src/blenderbim/blenderbim/bim/operator.py @@ -141,6 +141,25 @@ class SelectURIAttribute(bpy.types.Operator): context.window_manager.fileselect_add(self) return {"RUNNING_MODAL"} +class MultipleFileSelector(bpy.types.Operator): + bl_label = "Select Multiple Files" + bl_options = {"REGISTER", "UNDO"} + filepath: bpy.props.StringProperty(subtype="FILE_PATH") + files: bpy.props.CollectionProperty(name="File Path", type=bpy.types.OperatorFileListElement) + + def update_props(self, props, single_file: str, file_list: bpy.types.CollectionProperty): + dirname = os.path.dirname(self.filepath) + file_list.clear() + + for f in self.files: + new = file_list.add() + new.name = os.path.join(dirname, f.name) + setattr(props, single_file, self.filepath) + + + def invoke(self, context, event): + context.window_manager.fileselect_add(self) + return {"RUNNING_MODAL"} class SelectIfcFile(bpy.types.Operator, IFCFileSelector): bl_idname = "bim.select_ifc_file"