Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/bonsai/bonsai/bim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
operator.EditBlenderCollection,
operator.FileAssociate,
operator.FileUnassociate,
operator.LoadBlendMetadataAndIFC,
operator.OpenPath,
operator.OpenUpstream,
operator.OpenUri,
Expand Down
1 change: 1 addition & 0 deletions src/bonsai/bonsai/bim/module/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
operator.UnassignLibraryDeclaration,
operator.UnlinkIfc,
operator.UnloadLink,
operator.LoadBlendMetadataAndIFC,
workspace.ExploreHotkey,
prop.LibraryBreadcrumb,
prop.LibraryElement,
Expand Down
39 changes: 39 additions & 0 deletions src/bonsai/bonsai/bim/module/project/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3127,3 +3127,42 @@
tool.Blender.update_viewport()

return {"FINISHED"}

class LoadBlendMetadataAndIFC(bpy.types.Operator):
bl_idname = "bim.load_blend_metadata_and_ifc"
bl_label = "Load Blend Metadata and IFC"
bl_options = {"REGISTER", "UNDO"}
filepath: bpy.props.StringProperty(name="IFC File Path", default="")

def execute(self, context):
ifc_file = self.filepath
if not ifc_file:
props = tool.Blender.get_bim_props()
ifc_file = getattr(props, "ifc_file", None)

if not ifc_file:
self.report({"WARNING"}, "No IFC file path set.")
return {"CANCELLED"}

suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix
if ifc_file.lower().endswith(".ifc"):
metadata_path = ifc_file[:-4] + suffix
else:
metadata_path = ifc_file + suffix

# Define a handler to load the IFC project after the blend file is loaded and context is restored
@persistent
def load_handler(*args):
bpy.app.handlers.load_post.remove(load_handler)
# After loading metadata, clear blend warning (no geometry loaded yet)
props = tool.Blender.get_bim_props()
props.has_blend_warning = False
# Load the IFC file into the current session (preserve layout)
bpy.ops.bim.load_project(filepath=ifc_file, should_start_fresh_session=False)
# Disable editing styles
bpy.ops.bim.disable_editing_styles()
self.report({"INFO"}, f"Loaded metadata and IFC: {metadata_path}, {ifc_file}")

bpy.app.handlers.load_post.append(load_handler)
bpy.ops.wm.open_mainfile(filepath=metadata_path)
return {"FINISHED"}

Check failure on line 3168 in src/bonsai/bonsai/bim/module/project/operator.py

View workflow job for this annotation

GitHub Actions / lint-formatting

Black Format Issue

Black formatting issue in /home/runner/work/IfcOpenShell/IfcOpenShell/src/bonsai/bonsai/bim/module/project/operator.py
30 changes: 0 additions & 30 deletions src/bonsai/bonsai/bim/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,36 +364,6 @@ def execute(self, context):
return {"FINISHED"}


class LoadBlendMetadataAndIFC(bpy.types.Operator):
bl_idname = "bim.load_blend_metadata_and_ifc"
bl_label = "Load Blend Metadata and IFC"
bl_options = {"REGISTER", "UNDO"}
filepath: bpy.props.StringProperty(name="IFC File Path", default="")

def execute(self, context):
ifc_file = self.filepath
if not ifc_file:
props = tool.Blender.get_bim_props()
ifc_file = getattr(props, "ifc_file", None)

if not ifc_file:
self.report({"WARNING"}, "No IFC file path set.")
return {"CANCELLED"}

suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix
if ifc_file.lower().endswith(".ifc"):
metadata_path = ifc_file[:-4] + suffix
else:
metadata_path = ifc_file + suffix
# Open the metadata blend file
bpy.ops.wm.open_mainfile(filepath=metadata_path)
# After loading metadata, clear blend warning (no geometry loaded yet)
props = tool.Blender.get_bim_props()
props.has_blend_warning = False
# Load the IFC file into the current session (preserve layout)
bpy.ops.bim.load_project(filepath=ifc_file, should_start_fresh_session=False)
self.report({"INFO"}, f"Loaded metadata and IFC: {metadata_path}, {ifc_file}")
return {"FINISHED"}


# TODO: Unused operator.
Expand Down
Loading