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

Function _coerce_entity

src/ifcedit/ifcedit/coerce.py:131–142  ·  view source on GitHub ↗

Resolve a step ID string like '123' or '#123' to an entity instance.

(value_str: str | int, lookup_file: ifcopenshell.file | None)

Source from the content-addressed store, hash-verified

129
130
131def _coerce_entity(value_str: str | int, lookup_file: ifcopenshell.file | None) -> ifcopenshell.entity_instance:
132 """Resolve a step ID string like '123' or '#123' to an entity instance."""
133 if lookup_file is None:
134 raise ValueError("Cannot resolve entity reference without an IFC model")
135 if isinstance(value_str, int):
136 entity_id = value_str
137 else:
138 entity_id = int(value_str.strip().lstrip("#"))
139 try:
140 return lookup_file.by_id(entity_id)
141 except RuntimeError:
142 raise ValueError(f"Entity #{entity_id} not found in model")
143
144
145def _coerce_entity_list(value_str: str, lookup_file: ifcopenshell.file | None) -> list[ifcopenshell.entity_instance]:

Callers 2

coerce_valueFunction · 0.85
_coerce_entity_listFunction · 0.85

Calls 1

by_idMethod · 0.45

Tested by

no test coverage detected