mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 10:51:13 +00:00
Fix #5256. Use layer collection visibility, not collection visibility to hide types.
This commit is contained in:
@@ -1137,11 +1137,7 @@ class IfcImporter:
|
|||||||
except:
|
except:
|
||||||
# Occurs when reloading a project
|
# Occurs when reloading a project
|
||||||
pass
|
pass
|
||||||
project_collection = bpy.context.view_layer.layer_collection.children[self.project["blender"].name]
|
tool.Collector.reset_default_visibility()
|
||||||
if types_collection := project_collection.children.get("IfcTypeProduct"):
|
|
||||||
types_collection.hide_viewport = False
|
|
||||||
for obj in types_collection.collection.objects: # turn off all objects inside Types collection.
|
|
||||||
obj.hide_set(True)
|
|
||||||
|
|
||||||
def clean_mesh(self):
|
def clean_mesh(self):
|
||||||
obj = None
|
obj = None
|
||||||
@@ -1155,19 +1151,11 @@ class IfcImporter:
|
|||||||
if not last_obj:
|
if not last_obj:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Temporarily unhide types collection to make sure all objects will be cleaned
|
|
||||||
project_collection = bpy.context.view_layer.layer_collection.children[self.project["blender"].name]
|
|
||||||
if types_collection := project_collection.children.get("IfcTypeProduct"):
|
|
||||||
types_collection.hide_viewport = False
|
|
||||||
bpy.context.view_layer.objects.active = last_obj
|
|
||||||
|
|
||||||
bpy.ops.object.editmode_toggle()
|
bpy.ops.object.editmode_toggle()
|
||||||
bpy.ops.mesh.tris_convert_to_quads()
|
bpy.ops.mesh.tris_convert_to_quads()
|
||||||
bpy.ops.mesh.normals_make_consistent()
|
bpy.ops.mesh.normals_make_consistent()
|
||||||
bpy.ops.object.editmode_toggle()
|
bpy.ops.object.editmode_toggle()
|
||||||
|
|
||||||
if types_collection:
|
|
||||||
types_collection.hide_viewport = True
|
|
||||||
bpy.context.view_layer.objects.active = last_obj
|
bpy.context.view_layer.objects.active = last_obj
|
||||||
IfcStore.edited_objs.clear()
|
IfcStore.edited_objs.clear()
|
||||||
|
|
||||||
|
|||||||
@@ -59,11 +59,9 @@ class Collector(bonsai.core.tool.Collector):
|
|||||||
cls.link_to_collection_safe(obj, collection)
|
cls.link_to_collection_safe(obj, collection)
|
||||||
elif element.is_a("IfcLinearPositioningElement"):
|
elif element.is_a("IfcLinearPositioningElement"):
|
||||||
collection = cls._create_project_child_collection("IfcLinearPositioningElement")
|
collection = cls._create_project_child_collection("IfcLinearPositioningElement")
|
||||||
collection.hide_viewport = False
|
|
||||||
cls.link_to_collection_safe(obj, collection)
|
cls.link_to_collection_safe(obj, collection)
|
||||||
elif element.is_a("IfcReferent"):
|
elif element.is_a("IfcReferent"):
|
||||||
collection = cls._create_project_child_collection("IfcReferent")
|
collection = cls._create_project_child_collection("IfcReferent")
|
||||||
collection.hide_viewport = False
|
|
||||||
cls.link_to_collection_safe(obj, collection)
|
cls.link_to_collection_safe(obj, collection)
|
||||||
elif tool.Ifc.get_schema() == "IFC2X3" and element.is_a("IfcSpatialStructureElement"):
|
elif tool.Ifc.get_schema() == "IFC2X3" and element.is_a("IfcSpatialStructureElement"):
|
||||||
if collection := cls._create_own_collection(obj):
|
if collection := cls._create_own_collection(obj):
|
||||||
@@ -94,7 +92,6 @@ class Collector(bonsai.core.tool.Collector):
|
|||||||
cls.link_to_collection_safe(obj, collection)
|
cls.link_to_collection_safe(obj, collection)
|
||||||
else:
|
else:
|
||||||
collection = cls._create_project_child_collection("Unsorted")
|
collection = cls._create_project_child_collection("Unsorted")
|
||||||
collection.hide_viewport = False
|
|
||||||
cls.link_to_collection_safe(obj, collection)
|
cls.link_to_collection_safe(obj, collection)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -105,7 +102,8 @@ class Collector(bonsai.core.tool.Collector):
|
|||||||
collection = bpy.data.collections.new(name)
|
collection = bpy.data.collections.new(name)
|
||||||
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
|
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
|
||||||
project_obj.BIMObjectProperties.collection.children.link(collection)
|
project_obj.BIMObjectProperties.collection.children.link(collection)
|
||||||
collection.hide_viewport = True
|
if layer_collection := tool.Blender.get_layer_collection(collection):
|
||||||
|
layer_collection.hide_viewport = True
|
||||||
return collection
|
return collection
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -148,3 +146,23 @@ class Collector(bonsai.core.tool.Collector):
|
|||||||
if collection.children.find(obj_or_col.name) != -1:
|
if collection.children.find(obj_or_col.name) != -1:
|
||||||
return
|
return
|
||||||
collection.children.link(obj_or_col)
|
collection.children.link(obj_or_col)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def reset_default_visibility(cls):
|
||||||
|
project = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
|
||||||
|
project_collection = project.BIMObjectProperties.collection
|
||||||
|
for layer_collection in bpy.context.view_layer.layer_collection.children:
|
||||||
|
if layer_collection.collection == project_collection:
|
||||||
|
for layer_collection2 in layer_collection.children:
|
||||||
|
name = layer_collection2.collection.name
|
||||||
|
if name in (
|
||||||
|
"IfcTypeProduct",
|
||||||
|
"IfcOpeningElement",
|
||||||
|
"IfcStructuralItem",
|
||||||
|
"Unsorted",
|
||||||
|
):
|
||||||
|
layer_collection2.hide_viewport = True
|
||||||
|
elif name.startswith("IfcAnnotation"):
|
||||||
|
layer_collection2.hide_viewport = True
|
||||||
|
else:
|
||||||
|
layer_collection2.hide_viewport = False
|
||||||
|
|||||||
@@ -60,21 +60,6 @@ class Loader(bonsai.core.tool.Loader):
|
|||||||
def set_settings(cls, settings: bonsai.bim.import_ifc.IfcImportSettings) -> None:
|
def set_settings(cls, settings: bonsai.bim.import_ifc.IfcImportSettings) -> None:
|
||||||
cls.settings = settings
|
cls.settings = settings
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def create_project_collection(cls, name: str) -> bpy.types.Collection:
|
|
||||||
project_obj = tool.Ifc.get_object(tool.Ifc.get().by_type("IfcProject")[0])
|
|
||||||
project_collection = project_obj.BIMObjectProperties.collection
|
|
||||||
for collection in project_collection.children:
|
|
||||||
if collection.name == name:
|
|
||||||
return collection
|
|
||||||
collection = bpy.data.collections.new(name)
|
|
||||||
project_collection.children.link(collection)
|
|
||||||
if name == "Types":
|
|
||||||
project_layer = bpy.context.view_layer.layer_collection.children.get(project_collection.name)
|
|
||||||
if project_layer:
|
|
||||||
project_layer.children[collection.name].hide_viewport = True
|
|
||||||
return collection
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_mesh_name_from_shape(cls, geometry: ifcopenshell.geom.ShapeType) -> str:
|
def get_mesh_name_from_shape(cls, geometry: ifcopenshell.geom.ShapeType) -> str:
|
||||||
representation_id = geometry.id
|
representation_id = geometry.id
|
||||||
|
|||||||
@@ -130,10 +130,11 @@ def main(
|
|||||||
if settings.drawing_guid:
|
if settings.drawing_guid:
|
||||||
found_guid = False
|
found_guid = False
|
||||||
for f in files:
|
for f in files:
|
||||||
try:
|
try:
|
||||||
f.by_guid(settings.drawing_guid)
|
f.by_guid(settings.drawing_guid)
|
||||||
found_guid = True
|
found_guid = True
|
||||||
except: pass
|
except:
|
||||||
|
pass
|
||||||
if not found_guid:
|
if not found_guid:
|
||||||
raise ValueError(f"Unable to find guid {settings.drawing_guid!r}")
|
raise ValueError(f"Unable to find guid {settings.drawing_guid!r}")
|
||||||
sr.setElevationRefGuid(settings.drawing_guid)
|
sr.setElevationRefGuid(settings.drawing_guid)
|
||||||
|
|||||||
Reference in New Issue
Block a user