diff --git a/src/blenderbim/blenderbim/bim/module/root/data.py b/src/blenderbim/blenderbim/bim/module/root/data.py index 2f8c503d68..6a2b348221 100644 --- a/src/blenderbim/blenderbim/bim/module/root/data.py +++ b/src/blenderbim/blenderbim/bim/module/root/data.py @@ -151,7 +151,7 @@ class IfcClassData: @classmethod def has_entity(cls) -> Union[ifcopenshell.entity_instance, None]: - obj = bpy.context.active_object + obj = tool.Blender.get_active_object() cls.element = None if not obj: return diff --git a/src/blenderbim/blenderbim/core/tool.py b/src/blenderbim/blenderbim/core/tool.py index 99462f8c54..bc4140b371 100644 --- a/src/blenderbim/blenderbim/core/tool.py +++ b/src/blenderbim/blenderbim/core/tool.py @@ -77,6 +77,7 @@ class Blender: def apply_bmesh(cls, mesh, bm, obj=None): pass def bmesh_join(cls, bm_a, bm_b, callback=None): pass def create_ifc_object(cls, ifc_class: str, name: Optional[str] = None, data=None): pass + def get_active_object(cls): pass def get_bmesh_for_mesh(cls, mesh, clean=False): pass def get_default_selection_keypmap(cls): pass def get_name(cls, ifc_class, name): pass diff --git a/src/blenderbim/blenderbim/tool/blender.py b/src/blenderbim/blenderbim/tool/blender.py index f0968a965a..55959a096a 100644 --- a/src/blenderbim/blenderbim/tool/blender.py +++ b/src/blenderbim/blenderbim/tool/blender.py @@ -125,6 +125,10 @@ class Blender(blenderbim.core.tool.Blender): i += 1 return f"{name} {i}" + @classmethod + def get_active_object(cls) -> bpy.types.Object: + return bpy.context.view_layer.objects.active + @classmethod def get_selected_objects(cls) -> set[bpy.types.Object]: if bpy.context.selected_objects: diff --git a/src/blenderbim/test/bim/feature/project.feature b/src/blenderbim/test/bim/feature/project.feature index 67036e0a76..7f218b7c13 100644 --- a/src/blenderbim/test/bim/feature/project.feature +++ b/src/blenderbim/test/bim/feature/project.feature @@ -28,6 +28,66 @@ Scenario: Create project - IFC2X3 And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" +Scenario: New project - metric (m) preset + Given an empty Blender session + When I press "bim.new_project(preset='metric_m')" + Then an IFC file exists + And the object "IfcProject/My Project" is an "IfcProject" + And the object "IfcSite/My Site" is an "IfcSite" + And the object "IfcBuilding/My Building" is an "IfcBuilding" + And the object "IfcBuildingStorey/My Storey" is an "IfcBuildingStorey" + And the object "IfcProject/My Project" is in the collection "IfcProject/My Project" + And the object "IfcSite/My Site" is in the collection "IfcSite/My Site" + And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" + And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" + +Scenario: New project - metric (mm) preset + Given an empty Blender session + When I press "bim.new_project(preset='metric_mm')" + Then an IFC file exists + And the object "IfcProject/My Project" is an "IfcProject" + And the object "IfcSite/My Site" is an "IfcSite" + And the object "IfcBuilding/My Building" is an "IfcBuilding" + And the object "IfcBuildingStorey/My Storey" is an "IfcBuildingStorey" + And the object "IfcProject/My Project" is in the collection "IfcProject/My Project" + And the object "IfcSite/My Site" is in the collection "IfcSite/My Site" + And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" + And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" + +Scenario: New project - imperial (ft) preset + Given an empty Blender session + When I press "bim.new_project(preset='imperial_ft')" + Then an IFC file exists + And the object "IfcProject/My Project" is an "IfcProject" + And the object "IfcSite/My Site" is an "IfcSite" + And the object "IfcBuilding/My Building" is an "IfcBuilding" + And the object "IfcBuildingStorey/My Storey" is an "IfcBuildingStorey" + And the object "IfcProject/My Project" is in the collection "IfcProject/My Project" + And the object "IfcSite/My Site" is in the collection "IfcSite/My Site" + And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" + And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" + +Scenario: New project - demo preset + Given an empty Blender session + When I press "bim.new_project(preset='demo')" + Then an IFC file exists + And the object "IfcProject/My Project" is an "IfcProject" + And the object "IfcSite/My Site" is an "IfcSite" + And the object "IfcBuilding/My Building" is an "IfcBuilding" + And the object "IfcBuildingStorey/My Storey" is an "IfcBuildingStorey" + And the object "IfcProject/My Project" is in the collection "IfcProject/My Project" + And the object "IfcSite/My Site" is in the collection "IfcSite/My Site" + And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" + And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" + And the object "IfcBeamType/B1" is an "IfcBeamType" + And the object "IfcWallType/WAL50" is an "IfcWallType" + +Scenario: New project - wizard + Given an empty Blender session + When I press "bim.new_project(preset='wizard')" + Then an IFC file does not exist + And the object "IfcProject/My Project" does not exist + Scenario: Append library element Given an empty IFC project When I press "bim.select_library_file(filepath='{cwd}/test/files/basic.ifc')" @@ -253,13 +313,6 @@ Scenario: Load project elements - auto offset of cartesian points When I press "bim.load_project(filepath='{cwd}/test/files/manual-geolocation-coords.ifc')" Then the object "IfcBuildingElementProxy/NAME" is at "0,0,0" -Scenario: Unload project - Given an empty Blender session - When I press "bim.load_project(filepath='{cwd}/test/files/basic.ifc', is_advanced=True)" - And I press "bim.unload_project" - Then an IFC file does not exist - And "scene.BIMProjectProperties.is_loading" is "False" - Scenario: Link IFC Given an empty IFC project When I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"