mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
RegenerateGlobalIds - more informative fixing duplicates
This commit is contained in:
@@ -54,18 +54,27 @@ class Patcher:
|
||||
|
||||
def patch(self):
|
||||
if self.only_duplicates:
|
||||
duplicates = 0
|
||||
invalid_ids = 0
|
||||
|
||||
guids = set()
|
||||
for element in self.file.by_type("IfcRoot"):
|
||||
if element.GlobalId in guids:
|
||||
element.GlobalId = ifcopenshell.guid.new()
|
||||
duplicates += 1
|
||||
elif len(element.GlobalId) != 22 or element.GlobalId[0] not in "0123":
|
||||
element.GlobalId = ifcopenshell.guid.new()
|
||||
invalid_ids += 1
|
||||
else:
|
||||
try:
|
||||
ifcopenshell.guid.expand(element.GlobalId)
|
||||
except:
|
||||
element.GlobalId = ifcopenshell.guid.new()
|
||||
invalid_ids += 1
|
||||
guids.add(element.GlobalId)
|
||||
|
||||
print("Replaced %s duplicate GlobalIds" % duplicates)
|
||||
print("Replaced %s invalid GlobalIds" % invalid_ids)
|
||||
else:
|
||||
for element in self.file.by_type("IfcRoot"):
|
||||
element.GlobalId = ifcopenshell.guid.new()
|
||||
|
||||
Reference in New Issue
Block a user