Fix errors creating objects if default container is hidden #6456

This commit is contained in:
Andrej730
2025-04-01 11:31:03 +05:00
parent 93e7d92076
commit 31c9f60bca
9 changed files with 16 additions and 8 deletions
+1 -1
View File
@@ -513,7 +513,7 @@ class BIM_OT_add_door(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = None
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
tool.Blender.select_object(obj)
bpy.ops.bim.add_door()
return {"FINISHED"}
@@ -170,7 +170,7 @@ class DumbProfileGenerator:
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbProfile"})
obj.select_set(True)
tool.Blender.select_object(obj)
return obj
@@ -316,7 +316,7 @@ class BIM_OT_add_railing(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = None
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
tool.Blender.select_object(obj)
bpy.ops.bim.add_railing()
return {"FINISHED"}
+1 -1
View File
@@ -550,7 +550,7 @@ class BIM_OT_add_roof(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = None
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
tool.Blender.select_object(obj)
bpy.ops.bim.add_roof()
return {"FINISHED"}
+1 -1
View File
@@ -193,7 +193,7 @@ class DumbSlabGenerator:
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer3"})
material = ifcopenshell.util.element.get_material(element)
material.LayerSetDirection = "AXIS3"
obj.select_set(True)
tool.Blender.select_object(obj)
return obj
+1 -1
View File
@@ -169,7 +169,7 @@ class BIM_OT_add_stair(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = None
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
tool.Blender.select_object(obj)
bpy.ops.bim.add_stair()
return {"FINISHED"}
+1 -1
View File
@@ -882,7 +882,7 @@ class DumbWallGenerator:
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer2"})
material = ifcopenshell.util.element.get_material(element)
material.LayerSetDirection = "AXIS2"
obj.select_set(True)
tool.Blender.select_object(obj)
return obj
def get_relating_type_class(self, relating_type):
+1 -1
View File
@@ -437,7 +437,7 @@ class BIM_OT_add_window(bpy.types.Operator, tool.Ifc.Operator):
bpy.ops.object.select_all(action="DESELECT")
bpy.context.view_layer.objects.active = None
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
tool.Blender.select_object(obj)
bpy.ops.bim.add_window()
return {"FINISHED"}
+8
View File
@@ -605,6 +605,10 @@ class Blender(bonsai.core.tool.Blender):
@classmethod
def set_object_selection(cls, obj: bpy.types.Object, state: bool = True):
"""Run ``Object.select_set`` but ignore errors if the object is hidden.
Therefore, doesn't guarantee that the object is actually selected.
"""
try:
obj.select_set(state)
except RuntimeError: # Trying to select a hidden object throws an error
@@ -612,10 +616,14 @@ class Blender(bonsai.core.tool.Blender):
@classmethod
def select_object(cls, obj: bpy.types.Object):
"""Shortcut for ``set_object_selection(obj, True)``."""
cls.set_object_selection(obj, True)
@classmethod
def deselect_object(cls, obj: bpy.types.Object, ensure_active_object: bool = True):
"""Deselect object (using ``set_object_selection``) and optionally ensure that active
object is not the deselected object (last selected object used to replace it as active).
"""
cls.set_object_selection(obj, False)
if ensure_active_object and bpy.context.view_layer.objects.active == obj:
if bpy.context.selected_objects: