Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/api/cost/add_cost_schedule.py
T

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

75 lines
2.8 KiB
Python
Raw Normal View History

# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 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 ifcopenshell.api.root
2021-04-03 19:46:39 +11:00
import ifcopenshell.util.date
from datetime import datetime
2024-05-09 14:18:36 +05:00
from typing import Optional
2021-04-03 19:46:39 +11:00
2024-05-15 10:55:29 +05:00
def add_cost_schedule(
file: ifcopenshell.file, name: Optional[str] = None, predefined_type: str = "NOTDEFINED"
) -> ifcopenshell.entity_instance:
"""Add a new cost schedule
2022-11-21 12:05:30 +09:00
A cost schedule is a group of cost items which typically represent a
cost plan or breakdown of the project. This may be used as an estimate,
bid, or actual cost.
2022-11-21 12:05:30 +09:00
Alternatively, a cost schedule may also represent a schedule of rates,
which include cost items which capture unit rates for different elements
or processes.
2022-11-21 12:05:30 +09:00
As such, creating a cost schedule is necessary prior to creating and
managing any cost items.
2022-11-21 12:05:30 +09:00
:param name: The name of the cost schedule.
:param predefined_type: The predefined type of the cost schedule, chosen
from a valid type in the IFC documentation for
IfcCostScheduleTypeEnum
:return: The newly created IfcCostSchedule entity
2022-11-21 12:05:30 +09:00
Example:
2023-01-10 10:16:28 +11:00
.. code:: python
2022-11-21 12:05:30 +09:00
schedule = ifcopenshell.api.cost.add_cost_schedule(model)
# Now that we have a cost schedule, we may add cost items to it
item = ifcopenshell.api.cost.add_cost_item(model, cost_schedule=schedule)
"""
cost_schedule = ifcopenshell.api.root.create_entity(
file,
ifc_class="IfcCostSchedule",
2025-03-14 10:43:47 +05:00
predefined_type=predefined_type,
name=name,
)
2024-05-09 14:59:23 +05:00
if file.schema == "IFC2X3":
cost_schedule.UpdateDate = createIfcDateAndTime(file, datetime.now())
else:
cost_schedule.UpdateDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime")
return cost_schedule
2024-05-09 14:59:23 +05:00
def createIfcDateAndTime(file: ifcopenshell.file, dt: datetime):
ifc_dt = file.create_entity("IfcDateAndTime")
ifc_dt.DateComponent = file.create_entity(
"IfcCalendarDate", **ifcopenshell.util.date.datetime2ifc(dt, "IfcCalendarDate")
)
ifc_dt.TimeComponent = file.create_entity("IfcLocalTime", **ifcopenshell.util.date.datetime2ifc(dt, "IfcLocalTime"))
return ifc_dt