From ac9e6cc661921c24e5aa70004ac87208247d7cc3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 14 Aug 2021 18:48:23 +1000 Subject: [PATCH] New convenience button to add an empty for a type with no representation --- src/blenderbim/Makefile | 2 +- .../blenderbim/bim/module/model/__init__.py | 3 +++ .../blenderbim/bim/module/model/product.py | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/Makefile b/src/blenderbim/Makefile index 78309ca686..63ceb6ce09 100644 --- a/src/blenderbim/Makefile +++ b/src/blenderbim/Makefile @@ -69,7 +69,7 @@ endif cp -r blenderbim/* dist/blenderbim/ # Provides IfcOpenShell Python functionality - cd dist/working && wget https://s3.amazonaws.com/ifcopenshell-builds/ifcblender-python-$(PYNUMBER)-v0.6.0-0087fa8-$(PLATFORM)64.zip + cd dist/working && wget https://s3.amazonaws.com/ifcopenshell-builds/ifcblender-python-$(PYNUMBER)-v0.6.0-2f3c79a-$(PLATFORM)64.zip cd dist/working && unzip ifcblender* cp -r dist/working/io_import_scene_ifc/ifcopenshell dist/blenderbim/libs/site/packages/ diff --git a/src/blenderbim/blenderbim/bim/module/model/__init__.py b/src/blenderbim/blenderbim/bim/module/model/__init__.py index bd456e2658..b87350482f 100644 --- a/src/blenderbim/blenderbim/bim/module/model/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/model/__init__.py @@ -2,6 +2,7 @@ import bpy from . import handler, prop, ui, grid, product, wall, slab, stair, door, window, opening, pie, workspace classes = ( + product.AddEmptyType, product.AddTypeInstance, product.AlignProduct, product.DynamicallyVoidProduct, @@ -41,6 +42,7 @@ def register(): bpy.types.VIEW3D_MT_mesh_add.append(door.add_object_button) bpy.types.VIEW3D_MT_mesh_add.append(window.add_object_button) bpy.types.VIEW3D_MT_mesh_add.append(opening.add_object_button) + bpy.types.VIEW3D_MT_add.append(product.add_empty_type_button) bpy.app.handlers.load_post.append(handler.load_post) wm = bpy.context.window_manager if wm.keyconfigs.addon: @@ -60,6 +62,7 @@ def unregister(): bpy.types.VIEW3D_MT_mesh_add.remove(door.add_object_button) bpy.types.VIEW3D_MT_mesh_add.remove(window.add_object_button) bpy.types.VIEW3D_MT_mesh_add.remove(opening.add_object_button) + bpy.types.VIEW3D_MT_add.remove(product.add_empty_type_button) wm = bpy.context.window_manager kc = wm.keyconfigs.addon if kc: diff --git a/src/blenderbim/blenderbim/bim/module/model/product.py b/src/blenderbim/blenderbim/bim/module/model/product.py index d3faa0e2ed..3d230403a7 100644 --- a/src/blenderbim/blenderbim/bim/module/model/product.py +++ b/src/blenderbim/blenderbim/bim/module/model/product.py @@ -8,6 +8,33 @@ from . import wall, slab, profile from blenderbim.bim.ifc import IfcStore from ifcopenshell.api.pset.data import Data as PsetData from mathutils import Vector, Matrix +from bpy_extras.object_utils import AddObjectHelper + + +class AddEmptyType(bpy.types.Operator, AddObjectHelper): + bl_idname = "bim.add_empty_type" + bl_label = "Add Empty Type" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + obj = bpy.data.objects.new("TYPEX", None) + for project in [c for c in context.view_layer.layer_collection.children if "IfcProject" in c.name]: + if not [c for c in project.children if "Types" in c.name]: + types = bpy.data.collections.new("Types") + project.collection.children.link(types) + for collection in [c for c in project.children if "Types" in c.name]: + collection.collection.objects.link(obj) + break + break + context.scene.BIMRootProperties.ifc_product = "IfcElementType" + bpy.ops.object.select_all(action="DESELECT") + context.view_layer.objects.active = obj + obj.select_set(True) + return {"FINISHED"} + + +def add_empty_type_button(self, context): + self.layout.operator(AddEmptyType.bl_idname, icon="FILE_3D") class AddTypeInstance(bpy.types.Operator):