ifcopenshell.validate to check unique guids (IfcRoot.UR1)

This commit is contained in:
Andrej730
2024-04-02 17:17:23 +05:00
parent 20a2fda066
commit bf9bddc867
8 changed files with 128 additions and 0 deletions
@@ -350,10 +350,28 @@ def validate(f: Union[ifcopenshell.file, str], logger: Logger, express_rules=Fal
log_internal_cpp_errors(filename, logger)
schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(f.schema_identifier)
used_guids: dict[str, ifcopenshell.entity_instance] = dict()
for inst in f:
if hasattr(logger, "set_state"):
logger.set_state("instance", inst)
if hasattr(inst, "GlobalId"):
guid = inst.GlobalId
if guid is not None and guid in used_guids:
rule = "Rule IfcRoot.UR1:\n The attribute GlobalId should be unique"
previous_element = used_guids[guid]
logger.error(
"On instance:\n %s\n %s\n%s\nViolated by:\n %s\n %s",
inst,
annotate_inst_attr_pos(inst, 0),
rule,
previous_element,
annotate_inst_attr_pos(previous_element, 0),
)
else:
used_guids[guid] = inst
entity, attrs = get_entity_attributes(schema, inst.is_a())
if entity.is_abstract():