diff --git a/src/bonsai/bonsai/bim/module/model/data.py b/src/bonsai/bonsai/bim/module/model/data.py index 32af7c9286..e9e0160615 100644 --- a/src/bonsai/bonsai/bim/module/model/data.py +++ b/src/bonsai/bonsai/bim/module/model/data.py @@ -82,6 +82,7 @@ class AuthoringData: cls.data["has_visible_boundaries"] = cls.has_visible_boundaries() cls.data["active_class"] = cls.active_class() cls.data["active_material_usage"] = cls.active_material_usage() + cls.data["has_extrusion"] = cls.has_extrusion() cls.data["is_representation_item_active"] = cls.is_representation_item_active() # After is_representation_item_active. cls.data["is_representation_item_swept_solid"] = cls.is_representation_item_swept_solid() @@ -247,6 +248,19 @@ class AuthoringData: if (obj := tool.Blender.get_active_object()) and (element := tool.Ifc.get_entity(obj)): return tool.Model.get_usage_type(element) + @classmethod + def has_extrusion(cls) -> bool: + if not (obj := tool.Blender.get_active_object()) or not ( + representation := tool.Geometry.get_active_representation(obj) + ): + return False + + # Skip representation items. + if not representation.is_a("IfcShapeRepresentation"): + return False + + return bool(tool.Model.get_extrusion(representation)) + @classmethod def is_representation_item_active(cls) -> bool: if not (obj := tool.Blender.get_active_object()): diff --git a/src/bonsai/bonsai/bim/module/model/workspace.py b/src/bonsai/bonsai/bim/module/model/workspace.py index 44ee6cab8c..db79fc445a 100644 --- a/src/bonsai/bonsai/bim/module/model/workspace.py +++ b/src/bonsai/bonsai/bim/module/model/workspace.py @@ -1053,7 +1053,7 @@ class EditObjectUI: row.label(text="Mode") if ui_context != "TOOL_HEADER" else row if AuthoringData.data["active_material_usage"] == "LAYER3": - if len(context.selected_objects) == 1: + if len(context.selected_objects) == 1 and AuthoringData.data["has_extrusion"]: row = cls.layout.row(align=True) if ui_context != "TOOL_HEADER" else row add_layout_hotkey_operator(row, "Edit Profile", "S_E", "", ui_context) elif ( @@ -1242,7 +1242,11 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator): if self.active_material_usage == "LAYER3": # Edit LAYER3 profile - if bpy.context.active_object and bpy.context.active_object.mode == "OBJECT": + if ( + active_object.mode == "OBJECT" + and (representation := tool.Geometry.get_active_representation(active_object)) + and tool.Model.get_extrusion(representation) + ): bpy.ops.bim.enable_editing_extrusion_profile() elif self.active_material_usage == "LAYER2": # Extend LAYER2 to cursor diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 8cfb2775a1..7fc727c225 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -484,7 +484,7 @@ class Geometry(bonsai.core.tool.Geometry): @classmethod def get_active_representation(cls, obj: bpy.types.Object) -> Union[ifcopenshell.entity_instance, None]: - """< IfcShapeRepresentation or None""" + """:return: IfcRepresentation/IfcRepresentationItem or None""" if obj.data and hasattr(obj.data, "BIMMeshProperties") and obj.data.BIMMeshProperties.ifc_definition_id: return tool.Ifc.get().by_id(obj.data.BIMMeshProperties.ifc_definition_id)