MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / MSP2Ifc

Class MSP2Ifc

src/ifc4d/ifc4d/msp2ifc.py:31–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29
30
31class MSP2Ifc:
32 def __init__(self, optionalColumns: list[str] = []):
33 self.xml = None
34 self.file = None
35 self.ns = None
36 self.work_plan = None
37 self.project = {}
38 self.calendars = {}
39 self.tasks = {}
40 self.optionalColumns = optionalColumns
41 self.resources = {}
42 self.RESOURCE_TYPES_MAPPING = {"1": "LABOR", "0": "MATERIAL", "2": None}
43
44 def execute(self):
45 self.parse_xml()
46 self.create_ifc()
47
48 def parse_xml(self):
49 tree = ET.parse(self.xml)
50 project = tree.getroot()
51 self.ns = {"pr": project.tag[1:].partition("}")[0]}
52 self.project["Name"] = project.findtext("pr:Name", namespaces=self.ns) or "Unnamed"
53 self.project["CalendarUID"] = project.findtext("pr:CalendarUID", namespaces=self.ns) or None
54 self.project["MinutesPerDay"] = project.findtext("pr:MinutesPerDay", namespaces=self.ns) or None
55 self.outline_level = 0
56 self.outline_parents = {}
57 self.parse_task_xml(project)
58 self.parse_calendar_xml(project)
59 # TODO Doesn't do anything right now
60 # self.parse_resources_xml(project)
61
62 def parse_relationship_xml(self, task):
63 relationships = {}
64 id = 0
65 if task.findall("pr:PredecessorLink", self.ns):
66 for relationship in task.findall("pr:PredecessorLink", self.ns):
67 relationships[id] = {
68 "PredecessorTask": relationship.find("pr:PredecessorUID", self.ns).text,
69 "Type": relationship.find("pr:Type", self.ns).text,
70 }
71 id += 1
72 return relationships
73
74 def parse_task_xml(self, project):
75 if self.project["MinutesPerDay"]:
76 hours_per_day = int(self.project["MinutesPerDay"]) / 60
77 else:
78 hours_per_day = 8
79
80 for task in project.find("pr:Tasks", self.ns):
81 task_id = task.find("pr:UID", self.ns).text
82 task_index_level = task.find("pr:OutlineLevel", self.ns).text
83 wbs_id = task.find("pr:WBS", self.ns).text
84 relationships = self.parse_relationship_xml(task)
85 outline_level = int(task.find("pr:OutlineLevel", self.ns).text)
86
87 if outline_level != 0:
88 parent_task = self.tasks[self.outline_parents[outline_level - 1]]

Callers 2

__main__.pyFile · 0.90
_executeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected