diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py
index 9c687641bd..e3726d5073 100644
--- a/src/bonsai/bonsai/bim/module/drawing/operator.py
+++ b/src/bonsai/bonsai/bim/module/drawing/operator.py
@@ -3050,10 +3050,21 @@ class AddReference(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
filter_glob: bpy.props.StringProperty(default="*.svg", options={"HIDDEN"})
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=True)
filename_ext = ".svg"
+
+ files: bpy.props.CollectionProperty(type=bpy.types.OperatorFileListElement)
+ directory: bpy.props.StringProperty(subtype='DIR_PATH')
def _execute(self, context):
- filepath = tool.Ifc.get_uri(self.filepath, use_relative_path=self.use_relative_path)
- core.add_document(tool.Ifc, tool.Drawing, "REFERENCE", uri=filepath)
+ # Handle both single and multiple file selection
+ if self.files:
+ for file_elem in self.files:
+ filepath = os.path.join(self.directory, file_elem.name)
+ uri = tool.Ifc.get_uri(filepath, use_relative_path=self.use_relative_path)
+ core.add_document(tool.Ifc, tool.Drawing, "REFERENCE", uri=uri)
+ else:
+ # Fallback for single file (backward compatibility)
+ filepath = tool.Ifc.get_uri(self.filepath, use_relative_path=self.use_relative_path)
+ core.add_document(tool.Ifc, tool.Drawing, "REFERENCE", uri=filepath)
class RemoveReference(bpy.types.Operator, tool.Ifc.Operator):
diff --git a/src/bonsai/test/tool/test_drawing.py b/src/bonsai/test/tool/test_drawing.py
index 040dfb8dbb..28f95614f8 100644
--- a/src/bonsai/test/tool/test_drawing.py
+++ b/src/bonsai/test/tool/test_drawing.py
@@ -927,3 +927,69 @@ class TestAddReferenceImage(NewFile):
uv_node = material_nodes["Texture Coordinate"]
assert len(uv_node.outputs["Generated"].links[:]) == 1
+
+class TestAddReference(NewFile):
+ def test_add_single_reference(self):
+ """Test adding a single reference file (backward compatibility)"""
+ bpy.ops.bim.create_project()
+ ifc_path = Path("test/files/temp/test.ifc").absolute()
+ bpy.ops.bim.save_project(filepath=str(ifc_path), should_save_as=True)
+
+ # Create a temporary SVG file
+ svg_path = Path("test/files/temp/reference.svg").absolute()
+ svg_path.parent.mkdir(parents=True, exist_ok=True)
+ with open(svg_path, "w") as f:
+ f.write('')
+
+ try:
+ # Add single reference
+ bpy.ops.bim.add_reference(filepath=str(svg_path))
+
+ # Verify reference was added
+ ifc = tool.Ifc.get()
+ references = [doc for doc in ifc.by_type("IfcDocumentInformation") if doc.Scope == "REFERENCE"]
+ assert len(references) == 1
+ assert references[0].Name == "reference"
+ finally:
+ # Cleanup
+ if svg_path.exists():
+ svg_path.unlink()
+
+ def test_add_multiple_references(self):
+ """Test adding multiple reference files at once"""
+ bpy.ops.bim.create_project()
+ ifc_path = Path("test/files/temp/test.ifc").absolute()
+ bpy.ops.bim.save_project(filepath=str(ifc_path), should_save_as=True)
+
+ # Create temporary SVG files
+ temp_dir = Path("test/files/temp").absolute()
+ temp_dir.mkdir(parents=True, exist_ok=True)
+
+ svg_files = []
+ for i in range(3):
+ svg_path = temp_dir / f"reference_{i}.svg"
+ with open(svg_path, "w") as f:
+ f.write('')
+ svg_files.append(svg_path)
+
+ try:
+ # Test by directly calling core.add_document multiple times
+ # (simulating what the operator does with multiple files)
+ ifc = tool.Ifc.get()
+ for svg_file in svg_files:
+ uri = tool.Ifc.get_uri(str(svg_file), use_relative_path=True)
+ from bonsai.bim import core
+ core.drawing.add_document(tool.Ifc, tool.Drawing, "REFERENCE", uri=uri)
+
+ # Verify all references were added
+ references = [doc for doc in ifc.by_type("IfcDocumentInformation") if doc.Scope == "REFERENCE"]
+ assert len(references) == 3
+
+ reference_names = {ref.Name for ref in references}
+ expected_names = {f"reference_{i}" for i in range(3)}
+ assert reference_names == expected_names
+ finally:
+ # Cleanup
+ for svg_file in svg_files:
+ if svg_file.exists():
+ svg_file.unlink()