mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
Fix #3407. Override Ctrl-S to the export IFC which checks for Blender projects.
1. No IFC --> Saves Blend file 2. IFC, unsaved Blend --> Saves IFC 3. IFC, saved Blend --> Saves IFC and Blend
This commit is contained in:
@@ -174,7 +174,6 @@ def register():
|
||||
bpy.app.handlers.redo_post.append(handler.redo_post)
|
||||
bpy.app.handlers.load_post.append(handler.load_post)
|
||||
bpy.app.handlers.load_post.append(handler.loadIfcStore)
|
||||
bpy.app.handlers.save_post.append(handler.ensureIfcExported)
|
||||
bpy.types.Scene.BIMProperties = bpy.props.PointerProperty(type=prop.BIMProperties)
|
||||
bpy.types.Screen.BIMAreaProperties = bpy.props.CollectionProperty(type=prop.BIMAreaProperties)
|
||||
bpy.types.Collection.BIMCollectionProperties = bpy.props.PointerProperty(type=prop.BIMCollectionProperties)
|
||||
@@ -224,7 +223,6 @@ def unregister():
|
||||
|
||||
bpy.app.handlers.load_post.remove(handler.load_post)
|
||||
bpy.app.handlers.load_post.remove(handler.loadIfcStore)
|
||||
bpy.app.handlers.save_post.remove(handler.ensureIfcExported)
|
||||
del bpy.types.Scene.BIMProperties
|
||||
del bpy.types.Collection.BIMCollectionProperties
|
||||
del bpy.types.Object.BIMObjectProperties
|
||||
|
||||
@@ -233,12 +233,6 @@ def redo_post(scene):
|
||||
IfcStore.reload_undo_redo_stack_objects()
|
||||
|
||||
|
||||
@persistent
|
||||
def ensureIfcExported(scene):
|
||||
if IfcStore.get_file() and not bpy.context.scene.BIMProperties.ifc_file:
|
||||
bpy.ops.export_ifc.bim("INVOKE_DEFAULT")
|
||||
|
||||
|
||||
def get_application(ifc):
|
||||
# TODO: cache this for even faster application retrieval. It honestly makes a difference on long scripts.
|
||||
version = get_application_version()
|
||||
|
||||
@@ -276,9 +276,6 @@ class BIM_PT_schedules(Panel):
|
||||
def draw_project_not_saved_ui(self):
|
||||
row = self.layout.row()
|
||||
row.label(text="Project Not Yet Saved", icon="ERROR")
|
||||
row = self.layout.row()
|
||||
op = row.operator("export_ifc.bim", icon="EXPORT", text="Save Project")
|
||||
op.should_save_as = False
|
||||
|
||||
|
||||
class BIM_PT_references(Panel):
|
||||
|
||||
@@ -20,9 +20,9 @@ import bpy
|
||||
from . import ui, prop, operator
|
||||
|
||||
classes = (
|
||||
operator.AppendEntireLibrary,
|
||||
operator.AppendLibraryElement,
|
||||
operator.AssignLibraryDeclaration,
|
||||
operator.AppendEntireLibrary,
|
||||
operator.ChangeLibraryElement,
|
||||
operator.CreateProject,
|
||||
operator.DisableEditingHeader,
|
||||
@@ -75,6 +75,11 @@ def register():
|
||||
kmi.properties.name = "BIM_MT_new_project"
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
km = wm.keyconfigs.addon.keymaps.new(name="Window", space_type="EMPTY")
|
||||
kmi = km.keymap_items.new("export_ifc.bim", "S", "PRESS", ctrl=True)
|
||||
kmi.properties.should_save_as = False
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.types.TOPBAR_MT_file.remove(ui.file_menu)
|
||||
|
||||
@@ -872,7 +872,7 @@ class ToggleLinkVisibility(bpy.types.Operator):
|
||||
|
||||
class ExportIFC(bpy.types.Operator):
|
||||
bl_idname = "export_ifc.bim"
|
||||
bl_label = "Export IFC"
|
||||
bl_label = "Save IFC"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
filename_ext = ".ifc"
|
||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml;*.ifcjson", options={"HIDDEN"})
|
||||
@@ -893,15 +893,13 @@ class ExportIFC(bpy.types.Operator):
|
||||
layout.prop(self, "json_compact")
|
||||
if bpy.data.is_saved:
|
||||
layout.prop(self, "use_relative_path")
|
||||
else:
|
||||
layout.label(text="Save the .blend file first ")
|
||||
layout.label(text="to use relative paths for .ifc.")
|
||||
|
||||
def invoke(self, context, event):
|
||||
self.save_as_invoked = False
|
||||
if not IfcStore.get_file():
|
||||
self.report({"ERROR"}, "No IFC project is available for export - create or import a project first.")
|
||||
if not tool.Ifc.get():
|
||||
bpy.ops.wm.save_mainfile("INVOKE_DEFAULT")
|
||||
return {"FINISHED"}
|
||||
|
||||
self.save_as_invoked = False
|
||||
if context.scene.BIMProperties.ifc_file and not self.should_save_as:
|
||||
self.filepath = context.scene.BIMProperties.ifc_file
|
||||
if not os.path.isabs(self.filepath):
|
||||
@@ -972,7 +970,10 @@ class ExportIFC(bpy.types.Operator):
|
||||
if bpy.data.is_saved and bpy.data.is_dirty and bpy.data.filepath:
|
||||
bpy.ops.wm.save_mainfile(filepath=bpy.data.filepath)
|
||||
blenderbim.bim.handler.purge_module_data()
|
||||
return {"FINISHED"}
|
||||
self.report({"INFO"}, f"IFC Project \"{os.path.basename(output_file)}\" Saved")
|
||||
|
||||
if bpy.data.is_saved:
|
||||
bpy.ops.wm.save_mainfile("INVOKE_DEFAULT")
|
||||
|
||||
@classmethod
|
||||
def description(cls, context, properties):
|
||||
|
||||
@@ -204,11 +204,11 @@ class BIM_PT_project(Panel):
|
||||
row.prop(props, "ifc_file", text="")
|
||||
row.operator("bim.reload_ifc_file", icon="FILE_REFRESH", text="")
|
||||
row.operator("bim.select_ifc_file", icon="FILE_FOLDER", text="")
|
||||
row.operator("bim.unload_project", text="", icon="CANCEL")
|
||||
else:
|
||||
row = self.layout.row()
|
||||
row.label(text="File Not Saved", icon="ERROR")
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
op = row.operator("export_ifc.bim", icon="FILE_TICK", text="Save Project")
|
||||
op.should_save_as = False
|
||||
row.operator("bim.unload_project", text="", icon="CANCEL")
|
||||
|
||||
def draw_create_project_ui(self, context):
|
||||
props = context.scene.BIMProperties
|
||||
|
||||
Reference in New Issue
Block a user