Use hide_set() for IfcSpaces instead of hide_viewport

Moves IfcSpace hiding from collection assignment to after scene
addition, allowing hide_set() to work properly once objects are
in the view layer. Fixes RuntimeError during IFC import.
This commit is contained in:
Ryan Schultz
2025-12-25 19:05:30 -06:00
parent 05f7ffcbcc
commit 96fe9b5398
3 changed files with 14 additions and 8 deletions
+8
View File
@@ -290,6 +290,7 @@ class IfcImporter:
self.profile_code("Load linked models")
self.add_project_to_scene()
self.profile_code("Add project to scene")
self.hide_ifc_spaces()
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 1000:
self.clean_mesh()
self.profile_code("Mesh cleaning")
@@ -1286,6 +1287,13 @@ class IfcImporter:
properties={"Aggregate_Index": aggregate_index, "Name": name},
)
def hide_ifc_spaces(self):
"""Hide IfcSpace objects after they've been added to the scene."""
for ifc_definition_id, obj in self.added_data.items():
if isinstance(obj, bpy.types.Object):
element = self.file.by_id(ifc_definition_id)
if element.is_a("IfcSpace"):
obj.hide_set(True)
class IfcImportSettings:
"""
+2 -4
View File
@@ -52,12 +52,12 @@ class Collector(bonsai.core.tool.Collector):
tool.Geometry.lock_object(obj)
element = (element.PartOfU or element.PartOfV or element.PartOfW)[0]
if not tool.Spatial.get_grid_props().is_visible:
obj.hide_viewport = True
obj.hide_set(True)
elif element.is_a("IfcGrid"):
if tool.Geometry.is_locked(element):
tool.Geometry.lock_object(obj)
if not tool.Spatial.get_grid_props().is_visible:
obj.hide_viewport = True
obj.hide_set(True)
if element.is_a("IfcProject"):
if tool.Geometry.is_locked(element):
@@ -73,8 +73,6 @@ class Collector(bonsai.core.tool.Collector):
tool.Geometry.lock_object(obj)
collection = cls._create_project_child_collection("IfcSpace")
cls.link_collection_object_safe(collection, obj)
if not tool.Spatial.get_spatial_props().is_visible:
obj.hide_viewport = True
elif element.is_a("IfcStructuralItem"):
collection = cls._create_project_child_collection("IfcStructuralItem")
cls.link_collection_object_safe(collection, obj)
+4 -4
View File
@@ -1213,18 +1213,18 @@ class Spatial(bonsai.core.tool.Spatial):
for element in elements:
if obj := tool.Ifc.get_object(element):
if obj.hide_viewport is True and is_visible:
obj.hide_viewport = False
obj.hide_set(False)
elif obj.hide_viewport is False and not is_visible:
obj.hide_viewport = True
obj.hide_set(True)
@classmethod
def set_grid_visibility(cls, is_visible: bool) -> None:
for element in tool.Ifc.get().by_type("IfcGrid") + tool.Ifc.get().by_type("IfcGridAxis"):
if obj := tool.Ifc.get_object(element):
if obj.hide_viewport is True and is_visible:
obj.hide_viewport = False
obj.hide_set(False)
elif obj.hide_viewport is False and not is_visible:
obj.hide_viewport = True
obj.hide_set(True)
@classmethod
def toggle_spaces_visibility_wired_and_textured(cls, spaces: list[ifcopenshell.entity_instance]) -> None: