From 87dc1d5d01f3ec63222dff62e126a565f43b67ca Mon Sep 17 00:00:00 2001 From: Ziad-I <68874104+Ziad-I@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:08:54 +0300 Subject: [PATCH] add old gantt ui if web ui is not running --- src/blenderbim/blenderbim/tool/sequence.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/blenderbim/blenderbim/tool/sequence.py b/src/blenderbim/blenderbim/tool/sequence.py index 696d3839af..b01ef21a42 100644 --- a/src/blenderbim/blenderbim/tool/sequence.py +++ b/src/blenderbim/blenderbim/tool/sequence.py @@ -1544,15 +1544,18 @@ class Sequence(blenderbim.core.tool.Sequence): def generate_gantt_browser_chart( cls, task_json: list[dict[str, Any]], work_schedule: ifcopenshell.entity_instance ) -> None: - # with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"), "w") as f: - # with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.mustache"), "r") as t: - # task_b64 = base64.b64encode(bytes(json.dumps(task_json), "utf-8")).decode("utf-8") - # f.write( - # pystache.render(t.read(), {"json_data": task_b64, "data": json.dumps(work_schedule.get_info())}) - # ) - # webbrowser.open("file://" + os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html")) - gantt_data = {"tasks": task_json, "work_schedule": work_schedule.get_info(recursive=True)} - tool.Web.send_webui_data(extra_data=gantt_data, extra_data_key="gantt_data", event="gantt_data") + if bpy.context.scene.WebProperties.is_connected: + gantt_data = {"tasks": task_json, "work_schedule": work_schedule.get_info(recursive=True)} + tool.Web.send_webui_data(extra_data=gantt_data, extra_data_key="gantt_data", event="gantt_data") + return + + with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html"), "w") as f: + with open(os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.mustache"), "r") as t: + task_b64 = base64.b64encode(bytes(json.dumps(task_json), "utf-8")).decode("utf-8") + f.write( + pystache.render(t.read(), {"json_data": task_b64, "data": json.dumps(work_schedule.get_info(recursive=True))}) + ) + webbrowser.open("file://" + os.path.join(bpy.context.scene.BIMProperties.data_dir, "gantt", "index.html")) @classmethod def is_filter_by_active_schedule(cls) -> bool: