mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -21,70 +21,63 @@ import ifcopenshell.util.date
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, name=None, predefined_type="NOTDEFINED", start_time=None):
|
||||
"""Add a new work plan
|
||||
def add_work_plan(file, name=None, predefined_type="NOTDEFINED", start_time=None) -> None:
|
||||
"""Add a new work plan
|
||||
|
||||
A work plan is a group of work schedules. Since work schedules may have
|
||||
different purposes, such as for maintenance or construction scheduling,
|
||||
baseline comparison, or phasing, work plans can be used to group related
|
||||
work schedules. At a minimum, it is recommended to use work plans to
|
||||
indicate whether the work schedules are for facility management or for
|
||||
construction scheduling.
|
||||
A work plan is a group of work schedules. Since work schedules may have
|
||||
different purposes, such as for maintenance or construction scheduling,
|
||||
baseline comparison, or phasing, work plans can be used to group related
|
||||
work schedules. At a minimum, it is recommended to use work plans to
|
||||
indicate whether the work schedules are for facility management or for
|
||||
construction scheduling.
|
||||
|
||||
:param name: The name of the work plan. Recommended to be "Maintenance"
|
||||
or "Construction" for the two main purposes.
|
||||
:type name: str, optional
|
||||
:param predefined_type: The type of work plan, used for baselining.
|
||||
Leave as "NOTDEFINED" if unsure.
|
||||
:type predefined_type: str
|
||||
:param start_time: The earliest start time when the schedules grouped
|
||||
within the work plan are relevant.
|
||||
:type start_time: str,datetime.time
|
||||
:return: The newly created IfcWorkPlan
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
:param name: The name of the work plan. Recommended to be "Maintenance"
|
||||
or "Construction" for the two main purposes.
|
||||
:type name: str, optional
|
||||
:param predefined_type: The type of work plan, used for baselining.
|
||||
Leave as "NOTDEFINED" if unsure.
|
||||
:type predefined_type: str
|
||||
:param start_time: The earliest start time when the schedules grouped
|
||||
within the work plan are relevant.
|
||||
:type start_time: str,datetime.time
|
||||
:return: The newly created IfcWorkPlan
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
# This will hold all our construction schedules
|
||||
work_plan = ifcopenshell.api.run("sequence.add_work_plan", model, name="Construction")
|
||||
# This will hold all our construction schedules
|
||||
work_plan = ifcopenshell.api.run("sequence.add_work_plan", model, name="Construction")
|
||||
|
||||
# This is one of our schedules in our work plan.
|
||||
schedule = ifcopenshell.api.run("sequence.add_work_schedule", model,
|
||||
name="Construction Schedule A", work_plan=work_plan)
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {
|
||||
"name": name,
|
||||
"predefined_type": predefined_type,
|
||||
"start_time": start_time or datetime.now(),
|
||||
}
|
||||
# This is one of our schedules in our work plan.
|
||||
schedule = ifcopenshell.api.run("sequence.add_work_schedule", model,
|
||||
name="Construction Schedule A", work_plan=work_plan)
|
||||
"""
|
||||
settings = {
|
||||
"name": name,
|
||||
"predefined_type": predefined_type,
|
||||
"start_time": start_time or datetime.now(),
|
||||
}
|
||||
|
||||
def execute(self):
|
||||
work_plan = ifcopenshell.api.run(
|
||||
"root.create_entity",
|
||||
self.file,
|
||||
ifc_class="IfcWorkPlan",
|
||||
predefined_type=self.settings["predefined_type"],
|
||||
name=self.settings["name"],
|
||||
)
|
||||
work_plan.CreationDate = ifcopenshell.util.date.datetime2ifc(
|
||||
datetime.now(), "IfcDateTime"
|
||||
)
|
||||
user = ifcopenshell.api.owner.settings.get_user(self.file)
|
||||
if user:
|
||||
work_plan.Creators = [user.ThePerson]
|
||||
work_plan.StartTime = ifcopenshell.util.date.datetime2ifc(
|
||||
self.settings["start_time"], "IfcDateTime"
|
||||
)
|
||||
work_plan = ifcopenshell.api.run(
|
||||
"root.create_entity",
|
||||
file,
|
||||
ifc_class="IfcWorkPlan",
|
||||
predefined_type=settings["predefined_type"],
|
||||
name=settings["name"],
|
||||
)
|
||||
work_plan.CreationDate = ifcopenshell.util.date.datetime2ifc(datetime.now(), "IfcDateTime")
|
||||
user = ifcopenshell.api.owner.settings.get_user(file)
|
||||
if user:
|
||||
work_plan.Creators = [user.ThePerson]
|
||||
work_plan.StartTime = ifcopenshell.util.date.datetime2ifc(settings["start_time"], "IfcDateTime")
|
||||
|
||||
context = self.file.by_type("IfcContext")[0]
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
self.file,
|
||||
definitions=[work_plan],
|
||||
relating_context=context,
|
||||
)
|
||||
return work_plan
|
||||
context = file.by_type("IfcContext")[0]
|
||||
ifcopenshell.api.run(
|
||||
"project.assign_declaration",
|
||||
file,
|
||||
definitions=[work_plan],
|
||||
relating_context=context,
|
||||
)
|
||||
return work_plan
|
||||
|
||||
Reference in New Issue
Block a user