Merge elements with same GUID or TAG

It's possible to merge elements with the same GUID or TAG?

I tried using Patch Merge Duplicate Types (https://blenderbim.org/docs-python/autoapi/ifcpatch/recipes/MergeDuplicateTypes/index.html) but when I open my ifc file in BIMcollab exists more than 1 element with the same TAG.

Tagged:

Comments

  • Do you have some example file? Your code should merge them fine, see the example below.

    import ifcopenshell
    import ifcpatch
    ifc_file = ifcopenshell.file()
    
    guid = ifcopenshell.guid.new()
    
    # merge by global id
    ifc_file.createIfcWallType(GlobalId=guid)
    ifc_file.createIfcWallType(GlobalId=guid)
    ifc_file.createIfcWallType(GlobalId=guid)
    print(len(ifc_file.by_type("IfcWallType"))) # 2
    ifcpatch.execute({"input": None, "file": ifc_file, "recipe": "MergeDuplicateTypes", "arguments": ["GlobalId"]})
    print(len(ifc_file.by_type("IfcWallType"))) # 1
    
    # merge by tag
    tag = "test tag"
    ifc_file.createIfcBeamType(Tag=tag)
    ifc_file.createIfcBeamType(Tag=tag)
    print(len(ifc_file.by_type("IfcBeamType"))) # 2
    ifcpatch.execute({"input": None, "file": ifc_file, "recipe": "MergeDuplicateTypes", "arguments": []})
    print(len(ifc_file.by_type("IfcBeamType"))) # 1
    
  • Here is an example. I zipped the file so I could upload it.

    Some elements with the same GUID:

    1E1yvzyVb0LAZDdant$cp5
    1E1yvzyVb0LAZDdant$cp6
    1E1yvzyVb0LAZDdant$cpH
    1E1yvzyVb0LAZDdant$cpi
    1E1yvzyVb0LAZDdant$cpj
    1E1yvzyVb0LAZDdant$cpm
    1E1yvzyVb0LAZDdant$cpn
    1E1yvzyVb0LAZDdant$cpo
    1E1yvzyVb0LAZDdant$cpp
    1E1yvzyVb0LAZDdant$cpR
    1E1yvzyVb0LAZDdant$cpz

  • @Zanoni said:
    Some elements with the same GUID:

    1E1yvzyVb0LAZDdant$cp5
    1E1yvzyVb0LAZDdant$cp6
    1E1yvzyVb0LAZDdant$cpH
    1E1yvzyVb0LAZDdant$cpi
    1E1yvzyVb0LAZDdant$cpj
    1E1yvzyVb0LAZDdant$cpm
    1E1yvzyVb0LAZDdant$cpn
    1E1yvzyVb0LAZDdant$cpo
    1E1yvzyVb0LAZDdant$cpp
    1E1yvzyVb0LAZDdant$cpR
    1E1yvzyVb0LAZDdant$cpz

    These are all different GUIDs.

  • @brunopostle In each guid informed there are 4 elements...

    1E1yvzyVb0LAZDdant$cp5 - There are 4 elements
    1E1yvzyVb0LAZDdant$cp6 – There are 4 elements

    .....

  • edited February 7

    All those guids are not types but occurrences, MergeDuplicateTypes merges only types. Though it does merge types of those elements if they have matching guids - e.g. 3694759, 3480919, 2388844, 359263 (guid 1E1yvzyVb0LAZDdant$cpj) IfcWallStandardCases are pointing to different types with the same guid 0utCMpdeTCJOHnXCC6IWFD and all those types are merged by ifcpatch.

    import ifcopenshell
    import ifcpatch
    
    filepath = r"duplicates - Copy.ifc"
    ifc_file = ifcopenshell.open(filepath)
    
    def get_elements_by_guid(guids):
        elements_by_guid = dict()
        for element in ifc_file:
            guid = getattr(element, "GlobalId", None)
            if guid in guids:
                elements_by_guid.setdefault(guid, list()).append(element)
        return elements_by_guid
    
    for guid, elements in get_elements_by_guid(guids).items():
        print(f"Found elements by {guid}: {len(elements)}")
        for elem in elements:
            print(f"\t{elem}")
    
    Found elements by 1E1yvzyVb0LAZDdant$cpz: 4
            #4549931=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpz',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#4549929,#4549930,$)
            #3531688=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpz',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#3531686,#3531687,$)
            #2637057=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpz',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#2637048,#2637056,$)
            #1021576=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpz',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#1021567,#1021575,$)
    Found elements by 1E1yvzyVb0LAZDdant$cpH: 4
            #4549699=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpH',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#4549697,#4549698,$)
            #3531708=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpH',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#3531706,#3531707,$)
            #2696430=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpH',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#2636910,#2636923,$)
            #1021636=IfcOpeningElement('1E1yvzyVb0LAZDdant$cpH',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8450422',$,'Opening',#1021622,#1021635,$)
    Found elements by 1E1yvzyVb0LAZDdant$cpj: 4
            #3694759=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpj',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244294',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694748,#3694758,'8244294')
            #3480919=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpj',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244294',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480917,#3480918,'8244294')
            #2388844=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpj',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244294',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388842,#2388843,'8244294')
            #359263=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpj',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244294',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#359261,#359262,'8244294')
    Found elements by 1E1yvzyVb0LAZDdant$cpi: 4
            #3694744=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpi',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244295',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694733,#3694743,'8244295')
            #3480913=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpi',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244295',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480911,#3480912,'8244295')
            #2388849=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpi',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244295',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388847,#2388848,'8244295')
            #276812=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpi',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244295',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276810,#276811,'8244295')
    Found elements by 1E1yvzyVb0LAZDdant$cpp: 4
            #3694729=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpp',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244312',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694718,#3694728,'8244312')
            #3480907=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpp',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244312',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480905,#3480906,'8244312')
            #2388854=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpp',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244312',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388852,#2388853,'8244312')
            #276806=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpp',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244312',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276804,#276805,'8244312')
    Found elements by 1E1yvzyVb0LAZDdant$cpo: 4
            #3694714=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpo',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244313',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694703,#3694713,'8244313')
            #3480901=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpo',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244313',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480899,#3480900,'8244313')
            #2388859=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpo',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244313',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388857,#2388858,'8244313')
            #276800=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpo',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244313',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276798,#276799,'8244313')
    Found elements by 1E1yvzyVb0LAZDdant$cpn: 4
            #3694699=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpn',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244314',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694688,#3694698,'8244314')
            #3480895=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpn',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244314',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480893,#3480894,'8244314')
            #2388864=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpn',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244314',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388862,#2388863,'8244314')
            #276794=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpn',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244314',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276792,#276793,'8244314')
    Found elements by 1E1yvzyVb0LAZDdant$cpm: 4
            #3694684=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpm',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244315',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694673,#3694683,'8244315')                                                         #3480889=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpm',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244315',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480887,#3480888,'8244315')                                                         #2388869=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpm',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244315',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388867,#2388868,'8244315')                                                         #276788=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpm',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244315',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276786,#276787,'8244315')                                                     Found elements by 1E1yvzyVb0LAZDdant$cp6: 4                                                                                                                                                                                                         
            #3694669=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp6',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244333',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694658,#3694668,'8244333')
            #3480883=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp6',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244333',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480881,#3480882,'8244333')
            #2388874=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp6',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244333',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388872,#2388873,'8244333')
            #276782=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp6',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244333',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276780,#276781,'8244333')
    Found elements by 1E1yvzyVb0LAZDdant$cp5: 4
            #3694654=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp5',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244334',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694643,#3694653,'8244334')
            #3480877=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp5',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244334',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480875,#3480876,'8244334')
            #2388879=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp5',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244334',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388877,#2388878,'8244334')
            #276771=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cp5',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244334',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#276769,#276770,'8244334')
    Found elements by 1E1yvzyVb0LAZDdant$cpR: 4
            #3694624=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpR',#3691594,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244336',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3694613,#3694623,'8244336')
            #3480865=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpR',#3479074,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244336',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#3480863,#3480864,'8244336')
            #2388889=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpR',#2337713,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244336',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#2388887,#2388888,'8244336')
            #359268=IfcWallStandardCase('1E1yvzyVb0LAZDdant$cpR',#275834,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm:8244336',$,'Basic Wall:PINTURA COR BRANCO NEVE 0,5cm',#359266,#359267,'8244336')
    
Sign In or Register to comment.