bim.merge_identical_objects for merging identical styles

Button location - https://i.imgur.com/3O8gHUn.png

Could also be used as a temporary workaround for #5446
This commit is contained in:
Andrej730
2024-10-03 16:15:11 +05:00
parent be9c9b2caa
commit c3e4ebd996
5 changed files with 128 additions and 2 deletions
+21
View File
@@ -19,6 +19,7 @@
import os
import bpy
import ifcopenshell
import ifcopenshell.util.schema
import bonsai.core.tool
import bonsai.tool as tool
from test.bim.bootstrap import NewFile
@@ -66,3 +67,23 @@ class TestPurgeHdf5Cache(NewFile):
# On Unix loaded files are not locked.
paths = [loaded_file_path] if os.name == "nt" else []
assert [f for f in cache_dir.iterdir() if f.suffix == ".h5"] == paths
class TestMergeIdenticalObject(NewFile):
def test_merge_identical_styles(self):
tool.Ifc.set(ifc := ifcopenshell.file())
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle")
style_types = [d.name() for d in ifcopenshell.util.schema.get_subtypes(declaration)]
for style_type in style_types:
ifc.create_entity(style_type, Name=style_type)
ifc.create_entity(style_type, Name=style_type)
ifc.create_entity(style_type, Name="NotToMerge")
if style_type == "IfcSurfaceStyle":
for style in ifc.by_type(style_type):
style.Styles = (ifc.create_entity("IfcSurfaceStyleShading"),)
elif style_type == "IfcFillAreaStyle":
for style in ifc.by_type(style_type):
style.FillStyles = (ifc.create_entity("IfcFillAreaStyleHatching"),)
merge_data = subject.merge_identical_objects("style")
assert merge_data == {style_type: [style_type] for style_type in style_types}