refactor: Abstract "SelectFMIfcFile" to "MultipleFileSelector".

The "MultipleFileSelector" class can be used by child classes to implement the option to select multiple files at once. It requires two properties, which it will update: A StringProperty for a single path and a CollectionProperty for a list of paths.
This commit is contained in:
Blender Defender
2024-07-09 21:47:44 +02:00
committed by Dion Moult
parent 16e8c504f3
commit bbd4e00972
2 changed files with 23 additions and 15 deletions
@@ -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"
+19
View File
@@ -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"