Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/project/create_file.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.7 KiB
Python
Raw Normal View History

# IfcOpenShell - IFC toolkit and geometry engine
2022-11-13 15:32:24 +11:00
# Copyright (C) 2021, 2022 Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import datetime
import ifcopenshell
2024-12-20 18:30:43 +05:00
import ifcopenshell.util.schema
2024-12-20 18:30:43 +05:00
def create_file(version: ifcopenshell.util.schema.IFC_SCHEMA = "IFC4") -> ifcopenshell.file:
"""Create a blank IFC model file object
2022-11-13 15:30:35 +11:00
Create a new IFC file object based on the nominated schema version. The
schema version you choose determines what type of IFC data you can store
in this model. The file is blank and contains no entities.
It also sets up header data for STEP file serialisation, such as the
current timestamp, IfcOpenShell as the preprocessor, and defaults to a
DesignTransferView MVD.
:param version: The schema version of the IFC file. Choose from
"IFC2X3", "IFC4", or "IFC4X3". If you have loaded in a custom
schema, you may specify that schema identifier here too.
:return: The created IFC file object.
2022-12-14 17:28:34 +11:00
Example:
2023-01-10 10:16:28 +11:00
.. code:: python
2022-12-14 17:28:34 +11:00
# Start a new model.
model = ifcopenshell.api.project.create_file()
2022-12-14 17:28:34 +11:00
# It's currently a blank model, so typically the first thing we do
# is create a project in it.
project = ifcopenshell.api.root.create_entity(model, ifc_class="IfcProject", name="Test")
2022-12-14 17:28:34 +11:00
# ... and off we go!
"""
settings = {"version": version}
file = ifcopenshell.file(schema=settings["version"])
file.wrapped_data.header.file_name.name = "/dev/null" # Hehehe
file.wrapped_data.header.file_name.time_stamp = (
datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).astimezone().replace(microsecond=0).isoformat()
)
file.wrapped_data.header.file_name.preprocessor_version = "IfcOpenShell {}".format(ifcopenshell.version)
file.wrapped_data.header.file_name.originating_system = "IfcOpenShell {}".format(ifcopenshell.version)
file.wrapped_data.header.file_name.authorization = "Nobody"
file.wrapped_data.header.file_description.description = ("ViewDefinition[DesignTransferView]",)
return file