Collect all relationships for an element.
(model: ifcopenshell.file, element: ifcopenshell.entity_instance)
| 56 | |
| 57 | |
| 58 | def _all_relations(model: ifcopenshell.file, element: ifcopenshell.entity_instance) -> dict[str, Any]: |
| 59 | """Collect all relationships for an element.""" |
| 60 | result: dict[str, Any] = { |
| 61 | "id": element.id(), |
| 62 | "type": element.is_a(), |
| 63 | } |
| 64 | if hasattr(element, "Name") and element.Name: |
| 65 | result["name"] = element.Name |
| 66 | |
| 67 | # Hierarchy (upward) |
| 68 | hierarchy: dict[str, Any] = {} |
| 69 | parent = ifcopenshell.util.element.get_parent(element) |
| 70 | if parent is not None: |
| 71 | hierarchy["parent"] = _ref(parent) |
| 72 | container = ifcopenshell.util.element.get_container(element) |
| 73 | if container is not None: |
| 74 | hierarchy["container"] = _ref(container) |
| 75 | aggregate = ifcopenshell.util.element.get_aggregate(element) |
| 76 | if aggregate is not None: |
| 77 | hierarchy["aggregate"] = _ref(aggregate) |
| 78 | nest = ifcopenshell.util.element.get_nest(element) |
| 79 | if nest is not None: |
| 80 | hierarchy["nest"] = _ref(nest) |
| 81 | filled_void = ifcopenshell.util.element.get_filled_void(element) |
| 82 | if filled_void is not None: |
| 83 | hierarchy["filled_void"] = _ref(filled_void) |
| 84 | voided_element = ifcopenshell.util.element.get_voided_element(element) |
| 85 | if voided_element is not None: |
| 86 | hierarchy["voided_element"] = _ref(voided_element) |
| 87 | if hierarchy: |
| 88 | result["hierarchy"] = hierarchy |
| 89 | |
| 90 | # Children (downward) |
| 91 | children: dict[str, Any] = {} |
| 92 | contained = ifcopenshell.util.element.get_contained(element) |
| 93 | if contained: |
| 94 | children["contained"] = _ref_list(contained) |
| 95 | parts = ifcopenshell.util.element.get_parts(element) |
| 96 | if parts: |
| 97 | children["parts"] = _ref_list(parts) |
| 98 | components = ifcopenshell.util.element.get_components(element) |
| 99 | if components: |
| 100 | children["components"] = _ref_list(components) |
| 101 | openings = list(ifcopenshell.util.element.get_openings(element)) |
| 102 | if openings: |
| 103 | children["openings"] = _ref_list(openings) |
| 104 | if children: |
| 105 | result["children"] = children |
| 106 | |
| 107 | # Type relationship |
| 108 | type_relationship: dict[str, Any] = {} |
| 109 | element_type = ifcopenshell.util.element.get_type(element) |
| 110 | if element_type is not None: |
| 111 | type_relationship["type_of"] = _ref(element_type) |
| 112 | try: |
| 113 | occurrences = ifcopenshell.util.element.get_types(element) |
| 114 | if occurrences: |
| 115 | type_relationship["occurrences"] = _ref_list(occurrences) |
no test coverage detected