Get linked IFC entity based on obj's ifc_definition_id. Return None if object is not linked to IFC or it's linked to non-existent element.
(
cls, obj: Union[IFC_CONNECTED_TYPE, tool.Geometry.TYPES_WITH_MESH_PROPERTIES]
)
| 138 | |
| 139 | @classmethod |
| 140 | def get_entity( |
| 141 | cls, obj: Union[IFC_CONNECTED_TYPE, tool.Geometry.TYPES_WITH_MESH_PROPERTIES] |
| 142 | ) -> Union[ifcopenshell.entity_instance, None]: |
| 143 | """Get linked IFC entity based on obj's ifc_definition_id. |
| 144 | |
| 145 | Return None if object is not linked to IFC or it's linked to non-existent element. |
| 146 | """ |
| 147 | ifc = IfcStore.get_file() |
| 148 | if not ifc or not obj: |
| 149 | return |
| 150 | |
| 151 | props = None |
| 152 | if isinstance(obj, bpy.types.Object): |
| 153 | props = tool.Blender.get_object_bim_props(obj) |
| 154 | elif isinstance(obj, bpy.types.Material): |
| 155 | props = tool.Style.get_material_style_props(obj) |
| 156 | else: |
| 157 | props = tool.Geometry.get_mesh_props(obj) |
| 158 | |
| 159 | if props and (ifc_definition_id := props.ifc_definition_id): |
| 160 | try: |
| 161 | return ifc.by_id(ifc_definition_id) |
| 162 | except RuntimeError: |
| 163 | pass |
| 164 | |
| 165 | @classmethod |
| 166 | def get_entity_by_id(cls, entity_id: int) -> Union[ifcopenshell.entity_instance, None]: |