Compare commits

..

1 Commits

Author SHA1 Message Date
Ryan Schultz 46640722b4 Fix PermissionError deleting locked HDF5 cache on Windows
When the hdf5 serializer constructor fails on an existing
file, the HDF5 C library retains the file handle on Windows.
Force gc.collect() before os.remove() to release it, and
catch PermissionError to skip the cache gracefully if the
file is still locked.

Generated with the assistance of an AI coding tool.
2026-03-29 09:51:15 -05:00
5 changed files with 9 additions and 86 deletions
+8 -1
View File
@@ -18,6 +18,7 @@
from __future__ import annotations
import gc
import hashlib
import os
import shutil
@@ -170,7 +171,13 @@ class IfcStore:
# No point to trying again the same operation.
return
os.remove(IfcStore.cache_path)
# Force GC to release any dangling HDF5 C-level file handle (Windows).
gc.collect()
try:
os.remove(IfcStore.cache_path)
except PermissionError as e:
print(f"Could not delete locked cache file '{cache_path.name}': {str(e)}. Skipping cache.")
return
try:
IfcStore.cache = ifcopenshell.geom.serializers.hdf5(
IfcStore.cache_path, cache_settings, serializer_settings
@@ -104,7 +104,6 @@ classes = (
profile.ExtendProfile,
profile.RecalculateProfile,
profile.Rotate90,
profile.SplitProfile,
profile.PatchNonParametricMepSegment,
roof.GenerateHippedRoof,
slab.DisableEditingExtrusionProfile,
@@ -849,57 +849,6 @@ class DumbProfileJoiner:
def create_matrix(self, p: Vector, x: Vector, y: Vector, z: Vector) -> Matrix:
return Matrix([x, y, z, p]).to_4x4().transposed()
def split(self, profile1: bpy.types.Object, target: Vector) -> None:
element1 = tool.Ifc.get_entity(profile1)
if not element1:
return
if tool.Ifc.is_moved(profile1):
bonsai.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=profile1)
axis1 = self.get_profile_axis(profile1)
intersect, cut_percentage = mathutils.geometry.intersect_point_line(target, *axis1)
if cut_percentage < 0 or cut_percentage > 1 or tool.Cad.is_x(cut_percentage, (0, 1)):
return
# Duplicate the profile element
profile2 = profile1.copy()
profile2.data = profile2.data.copy()
for collection in profile1.users_collection:
collection.objects.link(profile2)
bonsai.core.root.copy_class(tool.Ifc, tool.Collector, tool.Geometry, tool.Root, obj=profile2)
element2 = tool.Ifc.get_entity(profile2)
# Transfer ATEND connection from element1 to element2
relating_element = None
relating_connection = None
description = None
for conn in list(element1.ConnectedTo):
if conn.is_a("IfcRelConnectsPathElements") and conn.RelatingConnectionType == "ATEND":
relating_element = conn.RelatedElement
relating_connection = conn.RelatedConnectionType
description = conn.Description
bonsai.core.geometry.remove_connection(tool.Geometry, connection=conn)
for conn in list(element1.ConnectedFrom):
if conn.is_a("IfcRelConnectsPathElements") and conn.RelatedConnectionType == "ATEND":
relating_element = conn.RelatingElement
relating_connection = conn.RelatingConnectionType
description = conn.Description
bonsai.core.geometry.remove_connection(tool.Geometry, connection=conn)
if relating_element:
ifcopenshell.api.geometry.connect_path(
tool.Ifc.get(),
relating_element=relating_element,
related_element=element2,
relating_connection=relating_connection,
related_connection="ATEND",
description=description,
)
# Recreate both profiles with split axes
self.recreate_profile(element1, profile1, [axis1[0], intersect], [axis1[0], intersect])
self.recreate_profile(element2, profile2, [intersect, axis1[1]], [intersect, axis1[1]])
def get_profile_axis(self, obj: bpy.types.Object) -> list[Vector]:
z_values = [v[2] for v in obj.bound_box]
return [
@@ -908,29 +857,6 @@ class DumbProfileJoiner:
]
class SplitProfile(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.split_profile"
bl_label = "Split Profile"
bl_options = {"REGISTER", "UNDO"}
bl_description = (
"Split selected profile element into two elements at the Blender cursor location. "
"The cursor must be positioned on the element's axis."
)
@classmethod
def poll(cls, context):
if not tool.Model.has_selected_ifc_objects():
cls.poll_message_set("No IFC objects selected.")
return False
return True
def _execute(self, context):
selected_objs = tool.Model.get_selected_mesh_objects()
for obj in selected_objs:
DumbProfileJoiner().split(obj, context.scene.cursor.location)
return {"FINISHED"}
class RecalculateProfile(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.recalculate_profile"
bl_label = "Recalculate Profile"
@@ -937,14 +937,6 @@ class EditObjectUI:
row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row
add_layout_hotkey_operator(row, "Mitre", "S_Y", "", ui_context)
row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row
add_layout_hotkey_operator(
row,
"Split",
"S_K",
"Split selected Element into two Elements at the cursor location\n\nHotkey: ⇧ K",
ui_context,
)
row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row
add_layout_hotkey_operator(row, "Rotate 90", "S_R", bpy.ops.bim.rotate_90.__doc__, ui_context)
else:
@@ -1369,8 +1361,6 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
return
if self.active_material_usage == "LAYER2":
bpy.ops.bim.split_wall()
elif self.active_material_usage == "PROFILE":
bpy.ops.bim.split_profile()
def hotkey_S_T(self):
if not bpy.context.selected_objects:
+1
View File
@@ -25,6 +25,7 @@ import bmesh
import bpy
import mathutils
import numpy as np
from bpy_extras import view3d_utils
from mathutils import Vector
import bonsai.core.tool