Resolve a step ID string like '123' or '#123' to an entity instance.
(value_str: str | int, lookup_file: ifcopenshell.file | None)
| 129 | |
| 130 | |
| 131 | def _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 | |
| 145 | def _coerce_entity_list(value_str: str, lookup_file: ifcopenshell.file | None) -> list[ifcopenshell.entity_instance]: |
no test coverage detected