Adds an entity including any dependent entities to an IFC file. If the entity already exists, it is not re-added. Existence of entity is checked by it's `.identity()`. :param inst: The entity instance to add :returns: An ifcopenshell.entity_instance
(self, inst: ifcopenshell.entity_instance, _id: int = None)
| 847 | return self[guid] |
| 848 | |
| 849 | def add(self, inst: ifcopenshell.entity_instance, _id: int = None) -> ifcopenshell.entity_instance: |
| 850 | """Adds an entity including any dependent entities to an IFC file. |
| 851 | If the entity already exists, it is not re-added. Existence of entity is checked by it's `.identity()`. |
| 852 | |
| 853 | :param inst: The entity instance to add |
| 854 | :returns: An ifcopenshell.entity_instance |
| 855 | """ |
| 856 | |
| 857 | if self.transaction: |
| 858 | max_id = self.wrapped_data.getMaxId() |
| 859 | inst.wrapped_data.this.disown() |
| 860 | result = entity_instance(self.wrapped_data.add(inst.wrapped_data, -1 if _id is None else _id), self) |
| 861 | if self.transaction: |
| 862 | added_elements = [e for e in self.traverse(result) if e.id() > max_id] |
| 863 | [self.transaction.store_create(e) for e in reversed(added_elements)] |
| 864 | return result |
| 865 | |
| 866 | def by_type(self, type: str, include_subtypes=True) -> list[ifcopenshell.entity_instance]: |
| 867 | """Return IFC objects filtered by IFC Type and wrapped with the entity_instance class. |