|
| 1 | +import os |
1 | 2 | import bpy |
2 | 3 | import json |
| 4 | +import pystache |
| 5 | +import webbrowser |
3 | 6 | import ifcopenshell.api |
4 | 7 | from datetime import datetime |
5 | 8 | from dateutil import parser |
@@ -783,3 +786,42 @@ def execute(self, context): |
783 | 786 | ) |
784 | 787 | Data.load(self.file) |
785 | 788 | return {"FINISHED"} |
| 789 | + |
| 790 | + |
| 791 | +class GenerateGanttChart(bpy.types.Operator): |
| 792 | + bl_idname = "bim.generate_gantt_chart" |
| 793 | + bl_label = "Generate Gantt Chart" |
| 794 | + work_schedule: bpy.props.IntProperty() |
| 795 | + |
| 796 | + def execute(self, context): |
| 797 | + self.file = IfcStore.get_file() |
| 798 | + self.json = [] |
| 799 | + for task_id in Data.work_schedules[self.work_schedule]["RelatedObjects"]: |
| 800 | + self.create_new_task_json(task_id) |
| 801 | + with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"), "w") as f: |
| 802 | + with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.mustache"), "r") as t: |
| 803 | + f.write(pystache.render(t.read(), {"json_data": json.dumps(self.json)})) |
| 804 | + webbrowser.open("file://" + os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html")) |
| 805 | + return {"FINISHED"} |
| 806 | + |
| 807 | + def create_new_task_json(self, task_id): |
| 808 | + task = self.file.by_id(task_id) |
| 809 | + self.json.append( |
| 810 | + { |
| 811 | + "pID": task.id(), |
| 812 | + "pName": task.Name, |
| 813 | + "pStart": task.TaskTime.ScheduleStart if task.TaskTime else "", |
| 814 | + "pEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "", |
| 815 | + "pPlanStart": task.TaskTime.ScheduleStart if task.TaskTime else "", |
| 816 | + "pPlanEnd": task.TaskTime.ScheduleFinish if task.TaskTime else "", |
| 817 | + "pClass": "ggroupblack", |
| 818 | + "pMile": 1 if task.IsMilestone else 0, |
| 819 | + "pComp": 0, |
| 820 | + "pGroup": 1, |
| 821 | + "pParent": task.Nests[0].RelatingObject.id() if task.Nests else 0, |
| 822 | + "pOpen": 1, |
| 823 | + "pCost": 1, |
| 824 | + } |
| 825 | + ) |
| 826 | + for task_id in Data.tasks[task_id]["RelatedObjects"]: |
| 827 | + self.create_new_task_json(task_id) |
0 commit comments