append_asset - check unique styles based on their name #6269

This commit is contained in:
Andrej730
2025-03-05 16:16:30 +05:00
parent 08b50bb9ea
commit 2987d38a31
2 changed files with 28 additions and 3 deletions
@@ -525,6 +525,7 @@ class Usecase:
if added_element := reuse_identities.get(element_identity):
return added_element
ifc_class = element.is_a()
attributes_ = None
def get_attributes() -> tuple[W.attribute, ...]:
@@ -550,6 +551,13 @@ class Usecase:
if existing_material is not None:
reuse_identities[element_identity] = existing_material
return existing_material
elif element.is_a("IfcPresentationStyle"):
style_name = element.Name
if style_name is not None:
existing_style = next((e for e in ifc_file.by_type(ifc_class) if e.Name == style_name), None)
if existing_style is not None:
reuse_identities[element_identity] = existing_style
return existing_style
attrs = {}
@@ -598,7 +606,7 @@ class Usecase:
attrs[attr_index] = attr_value
# Adding entity at the end just to keep it consistent with `file.add`.
new = ifc_file.create_entity(element.is_a())
new = ifc_file.create_entity(ifc_class)
reuse_identities[element_identity] = new
for attr_index, attr_value in attrs.items():
new[attr_index] = attr_value