Do not purge orphaned IfcDocumentReferences #6117

This commit is contained in:
Andrej730
2025-02-26 16:36:46 +05:00
parent 257f0b11f5
commit 24df52e2f7
+16 -3
View File
@@ -513,6 +513,7 @@ class PrintUnusedElementStats(bpy.types.Operator):
if self.ignore_styled_items: if self.ignore_styled_items:
ignore_classes += ["IfcStyledItem"] ignore_classes += ["IfcStyledItem"]
ignore_classes += [ ignore_classes += [
"IfcDocumentReference", # Document references for sheet elements (drawings, schedules, etc).
"IfcIndexedColourMap", # Only referenced by inverse attributes. "IfcIndexedColourMap", # Only referenced by inverse attributes.
"IfcIndexedTextureMap", # Only referenced by inverse attributes. "IfcIndexedTextureMap", # Only referenced by inverse attributes.
] ]
@@ -613,18 +614,30 @@ class PurgeUnusedElementsByClass(bpy.types.Operator, tool.Ifc.Operator):
"IfcUnitAssignment", "IfcUnitAssignment",
"IfcVirtualGridIntersection", "IfcVirtualGridIntersection",
] ]
whitelist_exceptions = {
# Document references for sheet elements (drawings, schedules, etc).
"IfcExternalReference": ("IfcDocumentReference",),
}
total_purged = 0 total_purged = 0
schema = tool.Ifc.schema()
while True: while True:
total_batches = 0 total_batches = 0
print("*" * 100) print("*" * 100)
total_batch_purged = 0 total_batch_purged = 0
for ifc_class in whitelisted_classes: for ifc_class in whitelisted_classes:
total_class_purged = 0 total_class_purged = 0
# Ensure class is present in the schema.
try: try:
elements = tool.Ifc.get().by_type(ifc_class) schema.declaration_by_name(ifc_class)
except: except RuntimeError:
continue # Probably not in this schema? continue
elements = tool.Ifc.get().by_type(ifc_class)
if ifc_class in whitelist_exceptions:
elements = [e for e in elements if not any(e.is_a(c) for c in whitelist_exceptions[ifc_class])]
to_purge = set() to_purge = set()
for element in elements: for element in elements:
try: try: