mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 08:45:22 +00:00
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:
@@ -290,6 +290,7 @@ class IfcImporter:
|
|||||||
self.profile_code("Load linked models")
|
self.profile_code("Load linked models")
|
||||||
self.add_project_to_scene()
|
self.add_project_to_scene()
|
||||||
self.profile_code("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:
|
if self.ifc_import_settings.should_clean_mesh and len(self.file.by_type("IfcElement")) < 1000:
|
||||||
self.clean_mesh()
|
self.clean_mesh()
|
||||||
self.profile_code("Mesh cleaning")
|
self.profile_code("Mesh cleaning")
|
||||||
@@ -1286,6 +1287,13 @@ class IfcImporter:
|
|||||||
properties={"Aggregate_Index": aggregate_index, "Name": name},
|
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:
|
class IfcImportSettings:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ class Collector(bonsai.core.tool.Collector):
|
|||||||
tool.Geometry.lock_object(obj)
|
tool.Geometry.lock_object(obj)
|
||||||
element = (element.PartOfU or element.PartOfV or element.PartOfW)[0]
|
element = (element.PartOfU or element.PartOfV or element.PartOfW)[0]
|
||||||
if not tool.Spatial.get_grid_props().is_visible:
|
if not tool.Spatial.get_grid_props().is_visible:
|
||||||
obj.hide_viewport = True
|
obj.hide_set(True)
|
||||||
elif element.is_a("IfcGrid"):
|
elif element.is_a("IfcGrid"):
|
||||||
if tool.Geometry.is_locked(element):
|
if tool.Geometry.is_locked(element):
|
||||||
tool.Geometry.lock_object(obj)
|
tool.Geometry.lock_object(obj)
|
||||||
if not tool.Spatial.get_grid_props().is_visible:
|
if not tool.Spatial.get_grid_props().is_visible:
|
||||||
obj.hide_viewport = True
|
obj.hide_set(True)
|
||||||
|
|
||||||
if element.is_a("IfcProject"):
|
if element.is_a("IfcProject"):
|
||||||
if tool.Geometry.is_locked(element):
|
if tool.Geometry.is_locked(element):
|
||||||
@@ -73,8 +73,6 @@ class Collector(bonsai.core.tool.Collector):
|
|||||||
tool.Geometry.lock_object(obj)
|
tool.Geometry.lock_object(obj)
|
||||||
collection = cls._create_project_child_collection("IfcSpace")
|
collection = cls._create_project_child_collection("IfcSpace")
|
||||||
cls.link_collection_object_safe(collection, obj)
|
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"):
|
elif element.is_a("IfcStructuralItem"):
|
||||||
collection = cls._create_project_child_collection("IfcStructuralItem")
|
collection = cls._create_project_child_collection("IfcStructuralItem")
|
||||||
cls.link_collection_object_safe(collection, obj)
|
cls.link_collection_object_safe(collection, obj)
|
||||||
|
|||||||
@@ -1213,18 +1213,18 @@ class Spatial(bonsai.core.tool.Spatial):
|
|||||||
for element in elements:
|
for element in elements:
|
||||||
if obj := tool.Ifc.get_object(element):
|
if obj := tool.Ifc.get_object(element):
|
||||||
if obj.hide_viewport is True and is_visible:
|
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:
|
elif obj.hide_viewport is False and not is_visible:
|
||||||
obj.hide_viewport = True
|
obj.hide_set(True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_grid_visibility(cls, is_visible: bool) -> None:
|
def set_grid_visibility(cls, is_visible: bool) -> None:
|
||||||
for element in tool.Ifc.get().by_type("IfcGrid") + tool.Ifc.get().by_type("IfcGridAxis"):
|
for element in tool.Ifc.get().by_type("IfcGrid") + tool.Ifc.get().by_type("IfcGridAxis"):
|
||||||
if obj := tool.Ifc.get_object(element):
|
if obj := tool.Ifc.get_object(element):
|
||||||
if obj.hide_viewport is True and is_visible:
|
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:
|
elif obj.hide_viewport is False and not is_visible:
|
||||||
obj.hide_viewport = True
|
obj.hide_set(True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def toggle_spaces_visibility_wired_and_textured(cls, spaces: list[ifcopenshell.entity_instance]) -> None:
|
def toggle_spaces_visibility_wired_and_textured(cls, spaces: list[ifcopenshell.entity_instance]) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user