ifcopenshell.file¶
Module Contents¶
- exception ifcopenshell.file.UndoSystemError(message: str, transaction: Transaction)¶
Bases:
ExceptionCommon base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- transaction¶
- class ifcopenshell.file.Transaction(ifc_file: ifcopenshell.file)¶
- batch() None¶
- commit() None¶
- get_element_inverses(element: ifcopenshell.entity_instance) ElementInverses¶
- has_element_reference(value: Any, element: ifcopenshell.entity_instance) bool¶
- rollback() None¶
- serialise_entity_instance(element: ifcopenshell.entity_instance) dict[str, Any]¶
- serialise_value(element, value) Any¶
- store_create(element: ifcopenshell.entity_instance) None¶
- store_delete(element: ifcopenshell.entity_instance) None¶
- store_edit(element: ifcopenshell.entity_instance, index: int, value: Any) None¶
- unbatch() None¶
- unserialise_value(element, value) Any¶
- batch_delete_ids: set[int]¶
- batch_delete_index = 0¶
- batch_inverses: list[ElementInverses]¶
- file: ifcopenshell.file¶
- is_batched = False¶
- operations: list[TransactionOperation]¶
- class ifcopenshell.file.file_mixin¶
Base class for containing IFC files.
Class has instance methods for filtering by element Id, Type, etc. Instantiated objects can be subscripted by Id or Guid
Example:
model = ifcopenshell.open(file_path) products = model.by_type("IfcProduct") print(products[0].id(), products[0].GlobalId) # 122 2XQ$n5SLP5MBLyL442paFx print(products[0] == model[122] == model["2XQ$n5SLP5MBLyL442paFx"]) # True
- add(inst: ifcopenshell.entity_instance, _id: int = None) ifcopenshell.entity_instance¶
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().
- Parameters:
inst – The entity instance to add
- Returns:
An ifcopenshell.entity_instance
- assign_header_from(other: ifcopenshell.file) None¶
- batch() None¶
Enable batch mode, a low-level mechanism to speed up deleting large subgraphs.
In batch mode
remove(entity)marks the entity for deletion instead of deleting it, andunbatch()deletes everything marked in one operation. The difference from usual removal: normally, removing an entity immediately edits it out of every entity that references it; in batch mode a referencing entity that is itself marked is left alone, so removing a face set and its thousands of faces does not rewrite the face set’s list once per face.
- begin_transaction() None¶
- by_type(type: str, include_subtypes=True) tuple[ifcopenshell.entity_instance, ...]¶
Return IFC objects filtered by IFC Type and wrapped with the entity_instance class.
If an IFC type class has subclasses, all entities of those subclasses are also returned.
- Parameters:
type – The case insensitive type of IFC class to return.
include_subtypes – Whether or not to return subtypes of the IFC class
- Raises:
RuntimeError – If type is not found in IFC schema.
- Returns:
A list of ifcopenshell.entity_instance objects
- create_entity(type: str, *args: Any, **kwargs: Any) ifcopenshell.entity_instance¶
Create a new IFC entity in the file.
You can also use dynamic methods similar to ifc_file.createIfcWall(…) to create IFC entities. They work exactly the same as if you would do ifc_file.create_entity(“IfcWall”, …) but the resulting typing is not as accurate as for create_entity due to a dynamic nature of those methods.
- Parameters:
type – Case insensitive name of the IFC class
args – The positional arguments of the IFC class
kwargs – The keyword arguments of the IFC class
- Returns:
An entity instance
Example:
f = ifcopenshell.file() f.create_entity("IfcPerson") # >>> #1=IfcPerson($,$,$,$,$,$,$,$) f.create_entity("IfcPerson", "Foobar") # >>> #2=IfcPerson('Foobar',$,$,$,$,$,$,$) f.create_entity("IfcPerson", Identification="Foobar") # >>> #3=IfcPerson('Foobar',$,$,$,$,$,$,$)
- discard_transaction() None¶
- end_transaction() None¶
- get_inverse(inst: ifcopenshell.entity_instance, allow_duplicate: Literal[False] = False, with_attribute_indices: bool = False) set[ifcopenshell.entity_instance]¶
- get_inverse(inst: ifcopenshell.entity_instance, allow_duplicate: Literal[True], with_attribute_indices: Literal[False] = False) list[ifcopenshell.entity_instance]
- get_inverse(inst: ifcopenshell.entity_instance, allow_duplicate: Literal[True], with_attribute_indices: Literal[True]) list[tuple[ifcopenshell.entity_instance, int]]
- get_inverse(inst: ifcopenshell.entity_instance, allow_duplicate: bool, with_attribute_indices: bool = False) list[ifcopenshell.entity_instance] | set[ifcopenshell.entity_instance]
Return a list of entities that reference this entity
Warning: this is a slow function, especially when there is a large number of inverses (such as for a shared owner history). If you are only interested in the total number of inverses (typically 0, 1, or N), consider using
get_total_inverses().- Parameters:
inst – The entity instance to get inverse relationships
allow_duplicate – Returns a list when True, set when False
with_attribute_indices – Returns pairs of <i, idx> where i[idx] is inst or contains inst. Requires allow_duplicate=True
- Returns:
A list or set of ifcopenshell.entity_instance objects.
- post_init(iden=None)¶
- redo() None¶
- remove(inst: ifcopenshell.entity_instance) None¶
Deletes an IFC object in the file.
Attribute values in other entity instances that reference the deleted object will be set to null. In the case of a list or set of references, the reference to the deleted will be removed from the aggregate.
- Parameters:
inst – The entity instance to delete
- set_history_size(size: int) None¶
- traverse(inst: ifcopenshell.entity_instance, max_levels: int | None = None, breadth_first: bool = False) tuple[ifcopenshell.entity_instance, ...]¶
Get a list of all referenced instances for a particular instance including itself
- Parameters:
inst – The entity instance to get all sub instances
max_levels – How far deep to recursively fetch sub instances. None or -1 means infinite.
breadth_first – Whether to use breadth-first search, the default is depth-first.
- Returns:
A list of ifcopenshell.entity_instance objects
- unbatch() None¶
Exit batch mode, deleting everything marked since
batch().
- undo() None¶
- write(path: os.PathLike | str, format: str | None = None, zipped: bool = False) None¶
Write ifc model to file.
- :param format: Force use of a specific format. Guessed from file name
if None. Supported formats : .ifc, .ifcZIP (equivalent to format=”.ifc” with zipped=True)
:param zipped: zip the file after it is written
Example:
model.write("path/to/model.ifc") model.write("path/to/model.ifcZIP") model.write("path/to/model.anyextension", format=".ifc")
- property future¶
- property history¶
- history_size: int = 64¶
- property mvd¶
- registry¶
- property schema: ifcopenshell.util.schema.IFC_SCHEMA¶
General IFC schema version: IFC2X3, IFC4, IFC4X3.
- property schema_version: tuple[int, int, int, int]¶
Numeric representation of the full IFC schema version.
E.g. IFC4X3_ADD2 is represented as (4, 3, 2, 0).
- property storage: rocksdb_file_storage | None¶
- Returns:
Optional[rocksdb_file_storage]: underlying key-value store interface when opened as a RocksDB-backed file
- to_delete: set[ifcopenshell.entity_instance] | None = None¶
Entities for batch removal.
- property transaction¶
- units: dict[str, ifcopenshell.entity_instance]¶
- class ifcopenshell.file.rocksdb_file_storage(file, prefix='')¶
- by_id(name)¶
- items()¶
- prefix(prefix)¶
- read(key)¶
- schema() ifcopenshell.util.schema.IFC_SCHEMA¶
General IFC schema version: IFC2X3, IFC4, IFC4X3.
- schema_identifier()¶
Full IFC schema version: IFC2X3_TC1, IFC4_ADD2, IFC4X3_ADD2, etc.
- file¶
- ifcopenshell.file.attribute_lookup(schema_name, entity_name)¶
- ifcopenshell.file.consume_buffer(val, inner)¶
- ifcopenshell.file.entity_name_lookup(schema_name, index)¶
- ifcopenshell.file.HEADER_FIELDS¶
- ifcopenshell.file.InverseReference¶
- ifcopenshell.file.binary_deserializers¶