pythonifc

Get the GUIDs contained in an IFCGROUP


how can I get the GUIDs contained in an IFCGROUP with IfcOpenShell?

http://ifcopenshell.org/

In this example I have two GUID IFCWalls in a IFCGroup

IFCGROUP GUI: 0MP5lKfsX6pBH1cXwBPLF0

IFCWALLSTANDARDCASE GUI: 0MP5lKfsX6pBH1cXwBPLEX

IFCWALLSTANDARDCASE GUI: 0MP5lKfsX6pBH1cXwBPLEA

I need a function that returns this:

res = getElements('0MP5lKfsX6pBH1cXwBPLF0')

print(res) // [0MP5lKfsX6pBH1cXwBPLEX, 0MP5lKfsX6pBH1cXwBPLEA]


Solution

  • Key to this is understanding inverse attributes (IsGroupedBy) and objectified relationships (http://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/lexical/IfcRelAssignsToGroup.htm)

    import operator
    import ifcopenshell
    
    ifc_file = ifcopenshell.open(...)
    group = ifc_file['0MP5lKfsX6pBH1cXwBPLF0']
    if group.IsGroupedBy:
        result = list(map(operator.attrgetter('GlobalId'), group.IsGroupedBy[0].RelatedObjects))