diff --git a/.gitignore b/.gitignore index 37f7ea9c98..d313811335 100644 --- a/.gitignore +++ b/.gitignore @@ -88,9 +88,6 @@ src/bonsai/bonsai/bim/data/gantt/jsgantt.js src/bonsai/bonsai/bim/data/gantt/jsgantt.css src/bonsai/bonsai/bim/data/webui/static/js/jquery.min.js -src/bonsai/drawings -src/bonsai/layouts - # ifcopenshell swig and compiled files src/ifcopenshell-python/ifcopenshell/_ifcopenshell_wrapper*.so src/ifcopenshell-python/ifcopenshell/ifcopenshell_wrapper.py diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 6379351de5..02bdf541ca 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -3461,6 +3461,15 @@ class LoadDrawings(bpy.types.Operator, tool.Ifc.Operator): bl_options = {"REGISTER", "UNDO"} + @classmethod + def poll(cls, context): + # Operator is not accessible through UI if IFC project is not saved, + # but adding poll check to avoid using Drawings UI in scripts with unsaved project. + if tool.Ifc.get_path(): + return True + cls.poll_message_set("IFC project is not saved.") + return False + def _execute(self, context): core.load_drawings(tool.Drawing) diff --git a/src/bonsai/bonsai/tool/project.py b/src/bonsai/bonsai/tool/project.py index bc2616fb15..def5255dfe 100644 --- a/src/bonsai/bonsai/tool/project.py +++ b/src/bonsai/bonsai/tool/project.py @@ -18,6 +18,7 @@ from __future__ import annotations import os +import shutil import bpy import ifcopenshell import ifcopenshell.api.document @@ -502,3 +503,11 @@ class Project(bonsai.core.tool.Project): d2 = v3 - v2 normals.append((v1, d1.cross(d2).normalized())) return normals + + @classmethod + def save_test_project(cls) -> None: + TMP = Path.cwd() / "test/files/temp" + # Clean up previous test project. + if TMP.exists(): + shutil.rmtree(TMP) + bpy.ops.bim.save_project(filepath=(TMP / "test_project.ifc").__str__(), should_save_as=True) diff --git a/src/bonsai/test/bim/feature/drawing.feature b/src/bonsai/test/bim/feature/drawing.feature index 084118b06b..6a24168e4b 100644 --- a/src/bonsai/test/bim/feature/drawing.feature +++ b/src/bonsai/test/bim/feature/drawing.feature @@ -157,13 +157,16 @@ Scenario: Remove drawing Scenario: Remove drawing - via object deletion Given an empty IFC project + And I save IFC project And I add a cube And the object "Cube" is selected And I look at the "Class" panel And I set the "Products" property to "IfcElement" And I set the "Class" property to "IfcWall" And I click "Assign IFC Class" - And I press "bim.add_drawing" + And I look at the "Drawings" panel + And I click "IMPORT" + And I click "ADD" And the variable "drawing" is "IfcStore.get_file().by_type('IfcAnnotation')[0].id()" And the collection "IfcAnnotation/PLAN_VIEW" exists And the object "IfcAnnotation/PLAN_VIEW" is selected diff --git a/src/bonsai/test/tool/test_drawing.py b/src/bonsai/test/tool/test_drawing.py index 9f499a01b1..040dfb8dbb 100644 --- a/src/bonsai/test/tool/test_drawing.py +++ b/src/bonsai/test/tool/test_drawing.py @@ -815,8 +815,9 @@ class TestDrawingMaintainingSheetPosition(NewFile): def test_run(self): props = tool.Drawing.get_document_props() bpy.ops.bim.create_project() + tool.Project.save_test_project() ifc = tool.Ifc.get() - sheet_path = Path.cwd() / "layouts" / "A01 - UNTITLED.svg" + sheet_path = Path(tool.Ifc.get_path()).parent / "layouts" / "A01 - UNTITLED.svg" bpy.ops.mesh.primitive_cube_add(size=10, location=(0, 0, 4)) obj = bpy.data.objects["Cube"] @@ -870,6 +871,7 @@ class TestDrawingMaintainingSheetPosition(NewFile): class TestDrawingStyles(NewFile): def setup_project_with_drawing(self): bpy.ops.bim.create_project() + tool.Project.save_test_project() bpy.ops.bim.load_drawings() bpy.ops.bim.add_drawing() ifc = tool.Ifc.get()