mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 03:49:58 +00:00
Open recent IFC project #3657
Example - https://imgur.com/a/EDfBTJS Paths to the opened IFC projects are now stored and then you can open them from File -> Open Recent IFC Project menu. It's done in very similar way to how Blender does it, list of files is stored in `Blender\4.1\config\recent-ifc-projects.txt`.
This commit is contained in:
@@ -24,6 +24,7 @@ import logging
|
||||
import tempfile
|
||||
import traceback
|
||||
import subprocess
|
||||
import datetime
|
||||
import numpy as np
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
@@ -655,6 +656,46 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
|
||||
is_advanced: bpy.props.BoolProperty(name="Enable Advanced Mode", default=False)
|
||||
use_relative_path: bpy.props.BoolProperty(name="Use Relative Path", default=False)
|
||||
should_start_fresh_session: bpy.props.BoolProperty(name="Should Start Fresh Session", default=True)
|
||||
use_detailed_tooltip: bpy.props.BoolProperty(default=False, options={"HIDDEN"})
|
||||
|
||||
@classmethod
|
||||
def description(cls, context, properties):
|
||||
tooltip = cls.bl_description
|
||||
if not properties.use_detailed_tooltip:
|
||||
return tooltip
|
||||
|
||||
filepath = properties.filepath
|
||||
if not filepath:
|
||||
return tooltip
|
||||
filepath = Path(filepath)
|
||||
tooltip += f".\n\n"
|
||||
if not filepath.exists():
|
||||
tooltip += "File does not exist"
|
||||
return tooltip
|
||||
|
||||
def get_modified_date(st_mtime: float) -> str:
|
||||
mod_time = datetime.datetime.fromtimestamp(st_mtime)
|
||||
|
||||
today = datetime.date.today()
|
||||
if mod_time.date() == today:
|
||||
return f"Today {mod_time.strftime('%I:%M %p')}"
|
||||
elif mod_time.date() == today - datetime.timedelta(days=1):
|
||||
return f"Yesterday {mod_time.strftime('%I:%M %p')}"
|
||||
return mod_time.strftime("%d %b %Y")
|
||||
|
||||
def get_file_size(size_bytes: float) -> str:
|
||||
if size_bytes < 1024 * 1024: # Less than 1 MiB
|
||||
size = size_bytes / 1024
|
||||
return f"{size:.0f} KiB"
|
||||
else:
|
||||
size = size_bytes / (1024 * 1024)
|
||||
return f"{size:.1f} MiB"
|
||||
|
||||
file_stat = filepath.stat()
|
||||
tooltip += f"Modified: {get_modified_date(file_stat.st_mtime)}"
|
||||
tooltip += f"\nSize: {get_file_size(file_stat.st_size)}"
|
||||
|
||||
return tooltip
|
||||
|
||||
def execute(self, context):
|
||||
@persistent
|
||||
@@ -683,10 +724,13 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
|
||||
for obj in bpy.data.objects:
|
||||
bpy.data.objects.remove(obj)
|
||||
|
||||
context.scene.BIMProperties.ifc_file = self.get_filepath()
|
||||
filepath = Path(self.get_filepath())
|
||||
context.scene.BIMProperties.ifc_file = str(filepath)
|
||||
context.scene.BIMProjectProperties.is_loading = True
|
||||
context.scene.BIMProjectProperties.total_elements = len(tool.Ifc.get().by_type("IfcElement"))
|
||||
tool.Blender.register_toolbar()
|
||||
tool.Blender.add_recent_ifc_project(filepath.absolute())
|
||||
|
||||
if not self.is_advanced:
|
||||
bpy.ops.bim.load_project_elements()
|
||||
except:
|
||||
@@ -703,6 +747,16 @@ class LoadProject(bpy.types.Operator, IFCFileSelector):
|
||||
IFCFileSelector.draw(self, context)
|
||||
|
||||
|
||||
class ClearRecentIFCProjects(bpy.types.Operator):
|
||||
bl_idname = "bim.clear_recent_ifc_projects"
|
||||
bl_label = "Clear Recent IFC Projects List"
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
def execute(self, context):
|
||||
tool.Blender.clear_recent_ifc_projects()
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class RevertProject(bpy.types.Operator, IFCFileSelector):
|
||||
bl_idname = "bim.revert_project"
|
||||
bl_label = "Revert IFC Project"
|
||||
|
||||
Reference in New Issue
Block a user