MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / get_entity

Method get_entity

src/bonsai/bonsai/tool/ifc.py:140–163  ·  view source on GitHub ↗

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]
    )

Source from the content-addressed store, hash-verified

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]:

Calls 5

get_object_bim_propsMethod · 0.80
get_mesh_propsMethod · 0.80
get_fileMethod · 0.45
by_idMethod · 0.45