2525
2626
2727class Patcher :
28- def __init__ (self , file : ifcopenshell .file , logger : Logger , attribute : str = "Tag" ):
28+ def __init__ (self , file : ifcopenshell .file , logger : Logger , attribute : str = "Tag" , should_merge_null : bool = True ):
2929 """Merge duplicate element types via the Tag or another attribute
3030
3131 Revit is notorious for creating many duplicate element types. Element
@@ -50,6 +50,8 @@ def __init__(self, file: ifcopenshell.file, logger: Logger, attribute: str = "Ta
5050 :param attribute: The name of the attribute to merge element types based
5151 on. Typically this will be "Tag" as it stores the unique ID from the
5252 proprietary BIM software.
53+ :param should_merge_null: If True, all elements with an empty attribute
54+ will be merged. If False, they will be kept separate.
5355
5456 Example:
5557
@@ -64,12 +66,15 @@ def __init__(self, file: ifcopenshell.file, logger: Logger, attribute: str = "Ta
6466 self .file = file
6567 self .logger = logger
6668 self .attribute = attribute
69+ self .should_merge_null = should_merge_null
6770
6871 def patch (self ):
69- key = self .attribute
7072 keys : dict [Any , ifcopenshell .entity_instance ] = {}
7173 for element_type in self .file .by_type ("IfcTypeObject" ):
72- original_type = keys .get (getattr (element_type , key ), None )
74+ key = getattr (element_type , self .attribute )
75+ if not key and not self .should_merge_null :
76+ continue
77+ original_type = keys .get (key , None )
7378 if original_type :
7479 elements = ifcopenshell .util .element .get_types (element_type )
7580 if elements :
@@ -78,7 +83,7 @@ def patch(self):
7883 ifcopenshell .util .element .replace_attribute (inverse , element_type , original_type )
7984 self .file .remove (element_type )
8085 else :
81- keys [getattr ( element_type , key ) ] = element_type
86+ keys [key ] = element_type
8287
8388 def assign_type (
8489 self , related_objects : list [ifcopenshell .entity_instance ], relating_type : ifcopenshell .entity_instance
0 commit comments