mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 03:05:33 +00:00
Fix errors creating objects if default container is hidden #6456
This commit is contained in:
@@ -513,7 +513,7 @@ class BIM_OT_add_door(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bpy.ops.object.select_all(action="DESELECT")
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
bpy.context.view_layer.objects.active = None
|
bpy.context.view_layer.objects.active = None
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
bpy.ops.bim.add_door()
|
bpy.ops.bim.add_door()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class DumbProfileGenerator:
|
|||||||
pset = ifcopenshell.api.run("pset.add_pset", self.file, product=element, name="EPset_Parametric")
|
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"})
|
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
|
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.ops.object.select_all(action="DESELECT")
|
||||||
bpy.context.view_layer.objects.active = None
|
bpy.context.view_layer.objects.active = None
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
bpy.ops.bim.add_railing()
|
bpy.ops.bim.add_railing()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ class BIM_OT_add_roof(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bpy.ops.object.select_all(action="DESELECT")
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
bpy.context.view_layer.objects.active = None
|
bpy.context.view_layer.objects.active = None
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
bpy.ops.bim.add_roof()
|
bpy.ops.bim.add_roof()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class DumbSlabGenerator:
|
|||||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer3"})
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer3"})
|
||||||
material = ifcopenshell.util.element.get_material(element)
|
material = ifcopenshell.util.element.get_material(element)
|
||||||
material.LayerSetDirection = "AXIS3"
|
material.LayerSetDirection = "AXIS3"
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class BIM_OT_add_stair(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bpy.ops.object.select_all(action="DESELECT")
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
bpy.context.view_layer.objects.active = None
|
bpy.context.view_layer.objects.active = None
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
bpy.ops.bim.add_stair()
|
bpy.ops.bim.add_stair()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -882,7 +882,7 @@ class DumbWallGenerator:
|
|||||||
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer2"})
|
ifcopenshell.api.run("pset.edit_pset", self.file, pset=pset, properties={"Engine": "Bonsai.DumbLayer2"})
|
||||||
material = ifcopenshell.util.element.get_material(element)
|
material = ifcopenshell.util.element.get_material(element)
|
||||||
material.LayerSetDirection = "AXIS2"
|
material.LayerSetDirection = "AXIS2"
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def get_relating_type_class(self, relating_type):
|
def get_relating_type_class(self, relating_type):
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ class BIM_OT_add_window(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bpy.ops.object.select_all(action="DESELECT")
|
bpy.ops.object.select_all(action="DESELECT")
|
||||||
bpy.context.view_layer.objects.active = None
|
bpy.context.view_layer.objects.active = None
|
||||||
bpy.context.view_layer.objects.active = obj
|
bpy.context.view_layer.objects.active = obj
|
||||||
obj.select_set(True)
|
tool.Blender.select_object(obj)
|
||||||
bpy.ops.bim.add_window()
|
bpy.ops.bim.add_window()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
@@ -605,6 +605,10 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def set_object_selection(cls, obj: bpy.types.Object, state: bool = True):
|
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:
|
try:
|
||||||
obj.select_set(state)
|
obj.select_set(state)
|
||||||
except RuntimeError: # Trying to select a hidden object throws an error
|
except RuntimeError: # Trying to select a hidden object throws an error
|
||||||
@@ -612,10 +616,14 @@ class Blender(bonsai.core.tool.Blender):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def select_object(cls, obj: bpy.types.Object):
|
def select_object(cls, obj: bpy.types.Object):
|
||||||
|
"""Shortcut for ``set_object_selection(obj, True)``."""
|
||||||
cls.set_object_selection(obj, True)
|
cls.set_object_selection(obj, True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deselect_object(cls, obj: bpy.types.Object, ensure_active_object: bool = True):
|
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)
|
cls.set_object_selection(obj, False)
|
||||||
if ensure_active_object and bpy.context.view_layer.objects.active == obj:
|
if ensure_active_object and bpy.context.view_layer.objects.active == obj:
|
||||||
if bpy.context.selected_objects:
|
if bpy.context.selected_objects:
|
||||||
|
|||||||
Reference in New Issue
Block a user