From 6b276b8aed596b01f7fc521c73b3ead4947dc55e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 20 Jul 2023 10:47:47 +0500 Subject: [PATCH] Small type manager refactor and more descriptions --- .../blenderbim/bim/module/model/prop.py | 21 ++++++----- .../blenderbim/bim/module/type/operator.py | 37 ++++++------------- 2 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/prop.py b/src/blenderbim/blenderbim/bim/module/model/prop.py index 976a61b22c..81b57ea7e6 100644 --- a/src/blenderbim/blenderbim/bim/module/model/prop.py +++ b/src/blenderbim/blenderbim/bim/module/model/prop.py @@ -137,16 +137,17 @@ class BIMModelProperties(PropertyGroup): type_page: bpy.props.IntProperty(name="Type Page", default=1, update=update_type_page) type_template: bpy.props.EnumProperty( items=( - ("MESH", "Custom Mesh", ""), - ("LAYERSET_AXIS2", "Vertical Layers", "For objects similar to walls"), - ("LAYERSET_AXIS3", "Horizontal Layers", "For objects similar to slabs"), - ("PROFILESET", "Extruded Profile", ""), - ("EMPTY", "Non-Geometric Type", ""), - ("WINDOW", "Window", ""), - ("DOOR", "Door", ""), - ("STAIR", "Stair", ""), - ("RAILING", "Railing", ""), - ("ROOF", "Roof", ""), + ("MESH", "Custom Mesh", "Use as a representation currently active object mesh or default cube if no object selected"), + ("LAYERSET_AXIS2", "Vertical Layers", "For objects similar to walls, will automatically add IfcMaterialLayerSet"), + ("LAYERSET_AXIS3", "Horizontal Layers", "For objects similar to slabs, will automatically add IfcMaterialLayerSet"), + ("PROFILESET", "Extruded Profile", "Create profile type object, automatically defines IfcMaterialProfileSet with the first profile from library"), + ("EMPTY", "Non-Geometric Type", "Start with an empty object"), + ("WINDOW", "Window", "Parametric window"), + ("DOOR", "Door", "Parametric door"), + ("STAIR", "Stair", "Parametric stair"), + ("RAILING", "Railing", "Parametric railing"), + ("ROOF", "Roof", "Parametric roof"), + ), name="Type Template", default="MESH", diff --git a/src/blenderbim/blenderbim/bim/module/type/operator.py b/src/blenderbim/blenderbim/bim/module/type/operator.py index 4a0e9e06cd..cb74a7aae6 100644 --- a/src/blenderbim/blenderbim/bim/module/type/operator.py +++ b/src/blenderbim/blenderbim/bim/module/type/operator.py @@ -212,6 +212,7 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW") if not body: props.type_class = props.type_class + self.report({"ERROR"}, "No Model/Body/MODEL_VIEW context found.") return {"FINISHED"} if template == "MESH": @@ -314,6 +315,7 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ifcopenshell.api.run( "material.assign_profile", ifc_file, material_profile=material_profile, profile=profile ) + elif template == "EMPTY": obj = bpy.data.objects.new(name, None) blenderbim.core.root.assign_class( @@ -329,7 +331,7 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ) elif template == "WINDOW": - mesh = bpy.data.meshes.new("IfcWindow") + mesh = bpy.data.meshes.new(name) obj = bpy.data.objects.new(name, mesh) element = blenderbim.core.root.assign_class( tool.Ifc, @@ -340,14 +342,11 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ifc_class="IfcWindowType" if tool.Ifc.get_schema() != "IFC2X3" else "IfcWindowStyle", should_add_representation=False, ) - 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_and_activate_single_object(context, obj) bpy.ops.bim.add_window() elif template == "DOOR": - mesh = bpy.data.meshes.new("IfcDoor") + mesh = bpy.data.meshes.new(name) obj = bpy.data.objects.new(name, mesh) element = blenderbim.core.root.assign_class( tool.Ifc, @@ -358,14 +357,11 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): ifc_class="IfcDoorType" if tool.Ifc.get_schema() != "IFC2X3" else "IfcDoorStyle", should_add_representation=False, ) - 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_and_activate_single_object(context, obj) bpy.ops.bim.add_door() elif template == "STAIR": - mesh = bpy.data.meshes.new("IfcStairFlight") + mesh = bpy.data.meshes.new(name) obj = bpy.data.objects.new(name, mesh) element = blenderbim.core.root.assign_class( tool.Ifc, @@ -377,14 +373,11 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): should_add_representation=True, context=body, ) - 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_and_activate_single_object(context, obj) bpy.ops.bim.add_stair() elif template == "RAILING": - mesh = bpy.data.meshes.new("IfcRailing") + mesh = bpy.data.meshes.new(name) obj = bpy.data.objects.new(name, mesh) element = blenderbim.core.root.assign_class( tool.Ifc, @@ -396,14 +389,11 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): should_add_representation=True, context=body, ) - 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_and_activate_single_object(context, obj) bpy.ops.bim.add_railing() elif template == "ROOF": - mesh = bpy.data.meshes.new("IfcRoof") + mesh = bpy.data.meshes.new(name) obj = bpy.data.objects.new(name, mesh) element = blenderbim.core.root.assign_class( tool.Ifc, @@ -415,10 +405,7 @@ class AddType(bpy.types.Operator, tool.Ifc.Operator): should_add_representation=True, context=body, ) - 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_and_activate_single_object(obj) bpy.ops.bim.add_roof() bpy.ops.bim.load_type_thumbnails(ifc_class=ifc_class)