mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 08:33:10 +00:00
replace api.run with static methods
This commit is contained in:
+39
-57
@@ -1,6 +1,9 @@
|
||||
from __future__ import annotations
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.control
|
||||
import ifcopenshell.api.resource
|
||||
import ifcopenshell.api.sequence
|
||||
import ifcopenshell.util.date
|
||||
from datetime import datetime, timedelta, date
|
||||
from typing import Union, Any, TypedDict
|
||||
@@ -81,7 +84,7 @@ class ScheduleIfcGenerator:
|
||||
if not self.file:
|
||||
self.file = self.create_boilerplate_ifc()
|
||||
if not self.work_plan:
|
||||
self.work_plan = ifcopenshell.api.run("sequence.add_work_plan", self.file)
|
||||
self.work_plan = ifcopenshell.api.sequence.add_work_plan(self.file)
|
||||
work_schedule = self.create_work_schedule()
|
||||
self.create_calendars()
|
||||
self.create_tasks(work_schedule)
|
||||
@@ -91,13 +94,13 @@ class ScheduleIfcGenerator:
|
||||
self.file.write(self.output)
|
||||
|
||||
def create_work_schedule(self) -> ifcopenshell.entity_instance:
|
||||
return ifcopenshell.api.run(
|
||||
"sequence.add_work_schedule", self.file, name=self.project["Name"], work_plan=self.work_plan
|
||||
return ifcopenshell.api.sequence.add_work_schedule(
|
||||
self.file, name=self.project["Name"], work_plan=self.work_plan
|
||||
)
|
||||
|
||||
def create_calendars(self) -> None:
|
||||
for calendar_id, calendar in self.calendars.items():
|
||||
calendar["ifc"] = ifcopenshell.api.run("sequence.add_work_calendar", self.file, name=calendar["Name"])
|
||||
calendar["ifc"] = ifcopenshell.api.sequence.add_work_calendar(self.file, name=calendar["Name"])
|
||||
calendar["ifc"].Identification = str(calendar_id)
|
||||
self.process_working_week(calendar["StandardWorkWeek"], calendar["ifc"])
|
||||
self.process_exceptions(calendar.get("HolidayOrExceptions"), calendar["ifc"])
|
||||
@@ -107,8 +110,8 @@ class ScheduleIfcGenerator:
|
||||
if day["ifc"] or not day.get("WorkTimes"):
|
||||
continue
|
||||
|
||||
day["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_work_time", self.file, work_calendar=calendar, time_type="WorkingTimes"
|
||||
day["ifc"] = ifcopenshell.api.sequence.add_work_time(
|
||||
self.file, work_calendar=calendar, time_type="WorkingTimes"
|
||||
)
|
||||
weekday_component = [self.day_map[day["DayOfWeek"]]]
|
||||
for day2 in week:
|
||||
@@ -120,25 +123,22 @@ class ScheduleIfcGenerator:
|
||||
day2["ifc"] = day["ifc"]
|
||||
|
||||
work_time_name = "Weekdays: {}".format(", ".join([str(c) for c in sorted(weekday_component)]))
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_time",
|
||||
ifcopenshell.api.sequence.edit_work_time(
|
||||
self.file,
|
||||
work_time=day["ifc"],
|
||||
attributes={"Name": work_time_name},
|
||||
)
|
||||
|
||||
recurrence = ifcopenshell.api.run(
|
||||
"sequence.assign_recurrence_pattern", self.file, parent=day["ifc"], recurrence_type="WEEKLY"
|
||||
recurrence = ifcopenshell.api.sequence.assign_recurrence_pattern(
|
||||
self.file, parent=day["ifc"], recurrence_type="WEEKLY"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_recurrence_pattern",
|
||||
ifcopenshell.api.sequence.edit_recurrence_pattern(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
attributes={"WeekdayComponent": weekday_component},
|
||||
)
|
||||
for work_time in day["WorkTimes"]:
|
||||
ifcopenshell.api.run(
|
||||
"sequence.add_time_period",
|
||||
ifcopenshell.api.sequence.add_time_period(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
start_time=work_time["Start"],
|
||||
@@ -159,11 +159,10 @@ class ScheduleIfcGenerator:
|
||||
def process_full_day_exceptions(
|
||||
self, year: int, month: int, month_data: dict[str, Any], calendar: ifcopenshell.entity_instance
|
||||
):
|
||||
work_time = ifcopenshell.api.run(
|
||||
"sequence.add_work_time", self.file, work_calendar=calendar, time_type="ExceptionTimes"
|
||||
work_time = ifcopenshell.api.sequence.add_work_time(
|
||||
self.file, work_calendar=calendar, time_type="ExceptionTimes"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_time",
|
||||
ifcopenshell.api.sequence.edit_work_time(
|
||||
self.file,
|
||||
work_time=work_time,
|
||||
attributes={
|
||||
@@ -172,14 +171,12 @@ class ScheduleIfcGenerator:
|
||||
"Finish": date(year, 12, 31),
|
||||
},
|
||||
)
|
||||
recurrence = ifcopenshell.api.run(
|
||||
"sequence.assign_recurrence_pattern",
|
||||
recurrence = ifcopenshell.api.sequence.assign_recurrence_pattern(
|
||||
self.file,
|
||||
parent=work_time,
|
||||
recurrence_type="YEARLY_BY_DAY_OF_MONTH",
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_recurrence_pattern",
|
||||
ifcopenshell.api.sequence.edit_recurrence_pattern(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
attributes={"DayComponent": month_data["FullDay"], "MonthComponent": [month]},
|
||||
@@ -192,8 +189,8 @@ class ScheduleIfcGenerator:
|
||||
if day["ifc"]:
|
||||
continue
|
||||
|
||||
day["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_work_time", self.file, work_calendar=calendar, time_type="ExceptionTimes"
|
||||
day["ifc"] = ifcopenshell.api.sequence.add_work_time(
|
||||
self.file, work_calendar=calendar, time_type="ExceptionTimes"
|
||||
)
|
||||
|
||||
day_component = [day["Day"]]
|
||||
@@ -205,8 +202,7 @@ class ScheduleIfcGenerator:
|
||||
# Don't process the next day, as we can group it
|
||||
day2["ifc"] = day["ifc"]
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_time",
|
||||
ifcopenshell.api.sequence.edit_work_time(
|
||||
self.file,
|
||||
work_time=day["ifc"],
|
||||
attributes={
|
||||
@@ -215,21 +211,18 @@ class ScheduleIfcGenerator:
|
||||
"Finish": date(year, 12, 31),
|
||||
},
|
||||
)
|
||||
recurrence = ifcopenshell.api.run(
|
||||
"sequence.assign_recurrence_pattern",
|
||||
recurrence = ifcopenshell.api.sequence.assign_recurrence_pattern(
|
||||
self.file,
|
||||
parent=day["ifc"],
|
||||
recurrence_type="YEARLY_BY_DAY_OF_MONTH",
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_recurrence_pattern",
|
||||
ifcopenshell.api.sequence.edit_recurrence_pattern(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
attributes={"DayComponent": day_component, "MonthComponent": [month]},
|
||||
)
|
||||
for work_time in day["WorkTimes"]:
|
||||
ifcopenshell.api.run(
|
||||
"sequence.add_time_period",
|
||||
ifcopenshell.api.sequence.add_time_period(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
start_time=work_time["Start"],
|
||||
@@ -245,8 +238,7 @@ class ScheduleIfcGenerator:
|
||||
def create_task_from_wbs(self, wbs: WBSEntry, work_schedule: ifcopenshell.entity_instance) -> None:
|
||||
if not self.wbs.get(wbs["ParentObjectId"]):
|
||||
wbs["ParentObjectId"] = None
|
||||
wbs["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_task",
|
||||
wbs["ifc"] = ifcopenshell.api.sequence.add_task(
|
||||
self.file,
|
||||
work_schedule=None if wbs["ParentObjectId"] else work_schedule,
|
||||
parent_task=self.wbs[wbs["ParentObjectId"]]["ifc"] if wbs["ParentObjectId"] else None,
|
||||
@@ -255,8 +247,7 @@ class ScheduleIfcGenerator:
|
||||
if wbs["ParentObjectId"]:
|
||||
if self.wbs[wbs["ParentObjectId"]]["ifc"]:
|
||||
identification = str(self.wbs[wbs["ParentObjectId"]]["ifc"].Identification) + "." + str(wbs["Code"])
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task",
|
||||
ifcopenshell.api.sequence.edit_task(
|
||||
self.file,
|
||||
task=wbs["ifc"],
|
||||
attributes={"Name": wbs["Name"], "Identification": str(identification)},
|
||||
@@ -270,14 +261,12 @@ class ScheduleIfcGenerator:
|
||||
wbs: Union[WBSEntry, None],
|
||||
work_schedule: Union[ifcopenshell.entity_instance, None],
|
||||
) -> None:
|
||||
activity["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_task",
|
||||
activity["ifc"] = ifcopenshell.api.sequence.add_task(
|
||||
self.file,
|
||||
work_schedule=None if wbs else work_schedule,
|
||||
parent_task=wbs["ifc"] if wbs else None,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task",
|
||||
ifcopenshell.api.sequence.edit_task(
|
||||
self.file,
|
||||
task=activity["ifc"],
|
||||
attributes={
|
||||
@@ -288,19 +277,17 @@ class ScheduleIfcGenerator:
|
||||
"PredefinedType": "CONSTRUCTION",
|
||||
},
|
||||
)
|
||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=activity["ifc"])
|
||||
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task=activity["ifc"])
|
||||
calendar = self.calendars[activity["CalendarObjectId"]]
|
||||
# Seems intermittently crashy - can we investigate for larger files?
|
||||
ifcopenshell.api.run(
|
||||
"control.assign_control",
|
||||
ifcopenshell.api.control.assign_control(
|
||||
self.file,
|
||||
**{
|
||||
"relating_control": calendar["ifc"],
|
||||
"related_object": activity["ifc"],
|
||||
},
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task_time",
|
||||
ifcopenshell.api.sequence.edit_task_time(
|
||||
self.file,
|
||||
task_time=task_time,
|
||||
attributes={
|
||||
@@ -323,14 +310,12 @@ class ScheduleIfcGenerator:
|
||||
"Finish to Finish": "FINISH_FINISH",
|
||||
}
|
||||
for relationship in self.relationships.values():
|
||||
rel_sequence = ifcopenshell.api.run(
|
||||
"sequence.assign_sequence",
|
||||
rel_sequence = ifcopenshell.api.sequence.assign_sequence(
|
||||
self.file,
|
||||
relating_process=self.activities[relationship["PredecessorActivity"]]["ifc"],
|
||||
related_process=self.activities[relationship["SuccessorActivity"]]["ifc"],
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_sequence",
|
||||
ifcopenshell.api.sequence.edit_sequence(
|
||||
self.file,
|
||||
rel_sequence=rel_sequence,
|
||||
attributes={"SequenceType": relationship["Type"]},
|
||||
@@ -338,8 +323,7 @@ class ScheduleIfcGenerator:
|
||||
lag = float(relationship["Lag"])
|
||||
if lag:
|
||||
calendar = self.calendars[self.activities[relationship["PredecessorActivity"]]["CalendarObjectId"]]
|
||||
ifcopenshell.api.run(
|
||||
"sequence.assign_lag_time",
|
||||
ifcopenshell.api.sequence.assign_lag_time(
|
||||
self.file,
|
||||
rel_sequence=rel_sequence,
|
||||
lag_value=timedelta(days=lag / float(calendar["HoursPerDay"] or 8)),
|
||||
@@ -353,14 +337,12 @@ class ScheduleIfcGenerator:
|
||||
parent = self.resources.get(resource.get("ParentObjectId"))
|
||||
if parent:
|
||||
if not parent.get("ifc"):
|
||||
parent["ifc"] = ifcopenshell.api.run(
|
||||
"resource.add_resource",
|
||||
parent["ifc"] = ifcopenshell.api.resource.add_resource(
|
||||
self.file,
|
||||
**{"ifc_class": "IfcCrewResource", "name": parent["Name"]},
|
||||
)
|
||||
if parent:
|
||||
resource["ifc"] = ifcopenshell.api.run(
|
||||
"resource.add_resource",
|
||||
resource["ifc"] = ifcopenshell.api.resource.add_resource(
|
||||
self.file,
|
||||
**{
|
||||
"parent_resource": parent["ifc"] if parent else None,
|
||||
@@ -369,8 +351,8 @@ class ScheduleIfcGenerator:
|
||||
},
|
||||
)
|
||||
else:
|
||||
resource["ifc"] = ifcopenshell.api.run(
|
||||
"resource.add_resource", self.file, **{"ifc_class": "IfcCrewResource", "name": resource["Name"]}
|
||||
resource["ifc"] = ifcopenshell.api.resource.add_resource(
|
||||
self.file, **{"ifc_class": "IfcCrewResource", "name": resource["Name"]}
|
||||
)
|
||||
|
||||
def create_boilerplate_ifc(self) -> None:
|
||||
|
||||
+13
-10
@@ -23,6 +23,10 @@ import ifcopenshell.api.resource
|
||||
import isodate
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.cost
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.unit
|
||||
import ifcopenshell.util.date
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.resource
|
||||
@@ -186,24 +190,23 @@ class Csv2Ifc:
|
||||
def create_resource(self, resource: dict[str, Any], parent: Union[ifcopenshell.entity_instance, None]) -> None:
|
||||
assert self.file
|
||||
if parent is None:
|
||||
resource["ifc"] = ifcopenshell.api.run("resource.add_resource", self.file, ifc_class=resource["class"])
|
||||
resource["ifc"] = ifcopenshell.api.resource.add_resource(self.file, ifc_class=resource["class"])
|
||||
else:
|
||||
resource["ifc"] = ifcopenshell.api.run(
|
||||
"resource.add_resource", self.file, parent_resource=parent, ifc_class=resource["class"]
|
||||
resource["ifc"] = ifcopenshell.api.resource.add_resource(
|
||||
self.file, parent_resource=parent, ifc_class=resource["class"]
|
||||
)
|
||||
resource["ifc"].Name = resource["Name"]
|
||||
if resource.get("Description", None):
|
||||
resource["ifc"].Description = resource.get("Description")
|
||||
if resource["Productivity"]:
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=resource["ifc"], name="EPset_Productivity")
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=resource["ifc"], name="EPset_Productivity")
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties=resource["Productivity"],
|
||||
)
|
||||
if resource["BaseCostValue"]:
|
||||
cost_value = ifcopenshell.api.run("cost.add_cost_value", self.file, parent=resource["ifc"])
|
||||
cost_value = ifcopenshell.api.cost.add_cost_value(self.file, parent=resource["ifc"])
|
||||
cost_value.AppliedValue = self.file.createIfcMonetaryMeasure(resource["BaseCostValue"])
|
||||
if usage_value := resource["usage"]:
|
||||
usage = ifcopenshell.api.resource.add_resource_time(self.file, resource=resource["ifc"])
|
||||
@@ -227,7 +230,7 @@ class Csv2Ifc:
|
||||
if unit:
|
||||
return unit
|
||||
else:
|
||||
unit = ifcopenshell.api.run("unit.add_si_unit", self.file, unit_type=unit_type)
|
||||
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type=unit_type)
|
||||
# unit = self.file.createIfcContextDependentUnit(
|
||||
# self.file.createIfcDimensionalExponents(0, 0, 0, 0, 0, 0, 0), "USERDEFINED", symbol
|
||||
# )
|
||||
@@ -236,8 +239,8 @@ class Csv2Ifc:
|
||||
|
||||
def create_boilerplate_ifc(self) -> None:
|
||||
self.file = ifcopenshell.file(schema="IFC4")
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.unit.assign_unit(self.file)
|
||||
|
||||
|
||||
class Ifc2CsvRow(NamedTuple):
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
import csv
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.sequence
|
||||
import ifcopenshell.util.date
|
||||
import locale
|
||||
import re
|
||||
@@ -136,14 +138,14 @@ class Csv2Ifc:
|
||||
if not self.file:
|
||||
self.create_boilerplate_ifc()
|
||||
if not self.work_plan:
|
||||
self.work_plan = ifcopenshell.api.run("sequence.add_work_plan", self.file)
|
||||
self.work_plan = ifcopenshell.api.sequence.add_work_plan(self.file)
|
||||
self.work_schedule = self.create_work_schedule()
|
||||
self.create_tasks(self.tasks)
|
||||
self.create_rel_sequences(self.tasks)
|
||||
|
||||
def create_boilerplate_ifc(self):
|
||||
self.file = ifcopenshell.file(schema="IFC4")
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
self.work_plan = self.file.create_entity("IfcWorkPlan")
|
||||
|
||||
def create_tasks(self, tasks, parent=None):
|
||||
@@ -161,16 +163,15 @@ class Csv2Ifc:
|
||||
self.create_rel_sequence(task)
|
||||
|
||||
def create_work_schedule(self):
|
||||
return ifcopenshell.api.run("sequence.add_work_schedule", self.file, name="import", work_plan=self.work_plan)
|
||||
return ifcopenshell.api.sequence.add_work_schedule(self.file, name="import", work_plan=self.work_plan)
|
||||
|
||||
def create_task(self, task, parent_task=None):
|
||||
if parent_task is None:
|
||||
task["ifc"] = ifcopenshell.api.run("sequence.add_task", self.file, work_schedule=self.work_schedule)
|
||||
task["ifc"] = ifcopenshell.api.sequence.add_task(self.file, work_schedule=self.work_schedule)
|
||||
else:
|
||||
task["ifc"] = ifcopenshell.api.run("sequence.add_task", self.file, parent_task=parent_task)
|
||||
task["ifc"] = ifcopenshell.api.sequence.add_task(self.file, parent_task=parent_task)
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task",
|
||||
ifcopenshell.api.sequence.edit_task(
|
||||
self.file,
|
||||
task=task["ifc"],
|
||||
attributes={
|
||||
@@ -179,9 +180,8 @@ class Csv2Ifc:
|
||||
# "IsMilestone": task["ScheduleStart"] == task["ScheduleFinish"],
|
||||
},
|
||||
)
|
||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=task["ifc"])
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task_time",
|
||||
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task=task["ifc"])
|
||||
ifcopenshell.api.sequence.edit_task_time(
|
||||
self.file,
|
||||
task_time=task_time,
|
||||
attributes={
|
||||
@@ -211,16 +211,14 @@ class Csv2Ifc:
|
||||
task_1 = self.get_entity_by_identification(self.tasks, rel["task_1"])
|
||||
task_2 = self.get_entity_by_identification(self.tasks, rel["task_2"])
|
||||
rel_type = self.sequence_type_map[rel["rel_type"]]
|
||||
rel_sequence = ifcopenshell.api.run(
|
||||
"sequence.assign_sequence",
|
||||
rel_sequence = ifcopenshell.api.sequence.assign_sequence(
|
||||
self.file,
|
||||
related_process=task_2,
|
||||
relating_process=task_1,
|
||||
sequence_type=rel_type,
|
||||
)
|
||||
if rel_type:
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_sequence",
|
||||
ifcopenshell.api.sequence.edit_sequence(
|
||||
self.file,
|
||||
rel_sequence=rel_sequence,
|
||||
attributes={"SequenceType": rel_type},
|
||||
|
||||
+32
-41
@@ -20,6 +20,10 @@ import datetime
|
||||
from datetime import timedelta, date
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.control
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.sequence
|
||||
import ifcopenshell.util.date
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
@@ -208,7 +212,7 @@ class MSP2Ifc:
|
||||
if not self.file:
|
||||
self.create_boilerplate_ifc()
|
||||
if not self.work_plan:
|
||||
self.work_plan = ifcopenshell.api.run("sequence.add_work_plan", self.file)
|
||||
self.work_plan = ifcopenshell.api.sequence.add_work_plan(self.file)
|
||||
work_schedule = self.create_work_schedule()
|
||||
self.create_calendars()
|
||||
self.create_tasks(work_schedule)
|
||||
@@ -216,7 +220,7 @@ class MSP2Ifc:
|
||||
|
||||
def create_boilerplate_ifc(self):
|
||||
self.file = ifcopenshell.file(schema="IFC4")
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
self.work_plan = self.file.create_entity("IfcWorkPlan")
|
||||
|
||||
def create_tasks(self, work_schedule):
|
||||
@@ -227,8 +231,8 @@ class MSP2Ifc:
|
||||
self.create_task(task, work_schedule=work_schedule)
|
||||
|
||||
def create_work_schedule(self):
|
||||
return ifcopenshell.api.run(
|
||||
"sequence.add_work_schedule", self.file, name=self.project["Name"], work_plan=self.work_plan
|
||||
return ifcopenshell.api.sequence.add_work_schedule(
|
||||
self.file, name=self.project["Name"], work_plan=self.work_plan
|
||||
)
|
||||
|
||||
def create_calendars(self):
|
||||
@@ -238,13 +242,12 @@ class MSP2Ifc:
|
||||
for calendar in self.calendars.values():
|
||||
if not has_work_or_exceptions(calendar):
|
||||
continue
|
||||
calendar["ifc"] = ifcopenshell.api.run("sequence.add_work_calendar", self.file, name=calendar["Name"])
|
||||
calendar["ifc"] = ifcopenshell.api.sequence.add_work_calendar(self.file, name=calendar["Name"])
|
||||
self.process_working_week(calendar["StandardWorkWeek"], calendar["ifc"])
|
||||
self.process_exceptions(calendar["HolidayOrExceptions"], calendar["ifc"])
|
||||
|
||||
def create_task(self, task, work_schedule=None, parent_task=None):
|
||||
task["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_task",
|
||||
task["ifc"] = ifcopenshell.api.sequence.add_task(
|
||||
self.file,
|
||||
work_schedule=work_schedule if work_schedule else None,
|
||||
parent_task=parent_task["ifc"] if parent_task else None,
|
||||
@@ -257,8 +260,7 @@ class MSP2Ifc:
|
||||
calendar = self.calendars[self.project["CalendarUID"]]["ifc"]
|
||||
|
||||
if calendar:
|
||||
ifcopenshell.api.run(
|
||||
"control.assign_control",
|
||||
ifcopenshell.api.control.assign_control(
|
||||
self.file,
|
||||
**{
|
||||
"relating_control": calendar,
|
||||
@@ -266,8 +268,7 @@ class MSP2Ifc:
|
||||
},
|
||||
)
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task",
|
||||
ifcopenshell.api.sequence.edit_task(
|
||||
self.file,
|
||||
task=task["ifc"],
|
||||
attributes={
|
||||
@@ -276,9 +277,8 @@ class MSP2Ifc:
|
||||
"IsMilestone": task["Start"] == task["Finish"],
|
||||
},
|
||||
)
|
||||
task_time = ifcopenshell.api.run("sequence.add_task_time", self.file, task=task["ifc"])
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_task_time",
|
||||
task_time = ifcopenshell.api.sequence.add_task_time(self.file, task=task["ifc"])
|
||||
ifcopenshell.api.sequence.edit_task_time(
|
||||
self.file,
|
||||
task_time=task_time,
|
||||
attributes={
|
||||
@@ -293,10 +293,9 @@ class MSP2Ifc:
|
||||
|
||||
# create pset for optional columns
|
||||
if len(self.optionalColumns):
|
||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=task["ifc"], name="Pset_MSP_Task")
|
||||
pset = ifcopenshell.api.pset.add_pset(self.file, product=task["ifc"], name="Pset_MSP_Task")
|
||||
|
||||
ifcopenshell.api.run(
|
||||
"pset.edit_pset",
|
||||
ifcopenshell.api.pset.edit_pset(
|
||||
self.file,
|
||||
pset=pset,
|
||||
properties={name: str(task[name]) for name in self.optionalColumns if task[name]},
|
||||
@@ -317,8 +316,8 @@ class MSP2Ifc:
|
||||
if day["ifc"]:
|
||||
continue
|
||||
|
||||
day["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_work_time", self.file, work_calendar=calendar, time_type="WorkingTimes"
|
||||
day["ifc"] = ifcopenshell.api.sequence.add_work_time(
|
||||
self.file, work_calendar=calendar, time_type="WorkingTimes"
|
||||
)
|
||||
|
||||
weekday_component = [day_map[day["DayType"]]]
|
||||
@@ -331,25 +330,22 @@ class MSP2Ifc:
|
||||
day2["ifc"] = day["ifc"]
|
||||
|
||||
work_time_name = "Weekdays: {}".format(", ".join([str(c) for c in sorted(weekday_component)]))
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_time",
|
||||
ifcopenshell.api.sequence.edit_work_time(
|
||||
self.file,
|
||||
work_time=day["ifc"],
|
||||
attributes={"Name": work_time_name},
|
||||
)
|
||||
|
||||
recurrence = ifcopenshell.api.run(
|
||||
"sequence.assign_recurrence_pattern", self.file, parent=day["ifc"], recurrence_type="WEEKLY"
|
||||
recurrence = ifcopenshell.api.sequence.assign_recurrence_pattern(
|
||||
self.file, parent=day["ifc"], recurrence_type="WEEKLY"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_recurrence_pattern",
|
||||
ifcopenshell.api.sequence.edit_recurrence_pattern(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
attributes={"WeekdayComponent": weekday_component},
|
||||
)
|
||||
for work_time in day["WorkingTimes"]:
|
||||
ifcopenshell.api.run(
|
||||
"sequence.add_time_period",
|
||||
ifcopenshell.api.sequence.add_time_period(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
start_time=work_time["Start"],
|
||||
@@ -367,15 +363,13 @@ class MSP2Ifc:
|
||||
if not task["PredecessorTasks"]:
|
||||
continue
|
||||
for predecessor in task["PredecessorTasks"].values():
|
||||
rel_sequence = ifcopenshell.api.run(
|
||||
"sequence.assign_sequence",
|
||||
rel_sequence = ifcopenshell.api.sequence.assign_sequence(
|
||||
self.file,
|
||||
related_process=task["ifc"],
|
||||
relating_process=self.tasks[predecessor["PredecessorTask"]]["ifc"],
|
||||
)
|
||||
if predecessor["Type"]:
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_sequence",
|
||||
ifcopenshell.api.sequence.edit_sequence(
|
||||
self.file,
|
||||
rel_sequence=rel_sequence,
|
||||
attributes={"SequenceType": self.sequence_type_map[predecessor["Type"]]},
|
||||
@@ -407,11 +401,10 @@ class MSP2Ifc:
|
||||
def process_exception(self, exception, calendar):
|
||||
if exception["ifc"] or not exception["FromDate"]:
|
||||
return
|
||||
exception["ifc"] = ifcopenshell.api.run(
|
||||
"sequence.add_work_time", self.file, work_calendar=calendar, time_type="ExceptionTimes"
|
||||
exception["ifc"] = ifcopenshell.api.sequence.add_work_time(
|
||||
self.file, work_calendar=calendar, time_type="ExceptionTimes"
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_work_time",
|
||||
ifcopenshell.api.sequence.edit_work_time(
|
||||
self.file,
|
||||
work_time=exception["ifc"],
|
||||
attributes={
|
||||
@@ -441,18 +434,16 @@ class MSP2Ifc:
|
||||
}
|
||||
else:
|
||||
return
|
||||
recurrence = ifcopenshell.api.run(
|
||||
"sequence.assign_recurrence_pattern",
|
||||
recurrence = ifcopenshell.api.sequence.assign_recurrence_pattern(
|
||||
self.file,
|
||||
parent=exception["ifc"],
|
||||
recurrence_type=recurrence_type,
|
||||
)
|
||||
ifcopenshell.api.run(
|
||||
"sequence.edit_recurrence_pattern", self.file, recurrence_pattern=recurrence, attributes=attributes
|
||||
ifcopenshell.api.sequence.edit_recurrence_pattern(
|
||||
self.file, recurrence_pattern=recurrence, attributes=attributes
|
||||
)
|
||||
for work_time in exception["WorkingTimes"] or []:
|
||||
ifcopenshell.api.run(
|
||||
"sequence.add_time_period",
|
||||
ifcopenshell.api.sequence.add_time_period(
|
||||
self.file,
|
||||
recurrence_pattern=recurrence,
|
||||
start_time=work_time["Start"],
|
||||
|
||||
Reference in New Issue
Block a user