Fix bug where context has no active_object when creating a new project from File > New with a preset

This commit is contained in:
Dion Moult
2024-06-29 22:20:02 +10:00
parent c68dcba087
commit 2efeb6edb3
4 changed files with 66 additions and 8 deletions
@@ -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
+1
View File
@@ -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
@@ -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:
@@ -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')"