From 177b8218ee3a194bb59796f8948d8650bbba26af Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 9 Jun 2024 16:53:04 +1000 Subject: [PATCH] Creating grids now uses tool.Collector.assign instead of reimplementing collection management --- .../blenderbim/bim/module/model/grid.py | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/grid.py b/src/blenderbim/blenderbim/bim/module/model/grid.py index a00720c2ed..120dd15766 100644 --- a/src/blenderbim/blenderbim/bim/module/model/grid.py +++ b/src/blenderbim/blenderbim/bim/module/model/grid.py @@ -28,23 +28,9 @@ def add_object(self, context): obj = bpy.data.objects.new("Grid", None) obj.name = "Grid" - collection = context.view_layer.active_layer_collection.collection - site = tool.Ifc.get().by_type("IfcSite") - if site: - site = site[0] - site_obj = tool.Ifc.get_object(site) - if site_obj: - collection = site_obj.BIMObjectProperties.collection or collection - - collection.objects.link(obj) - bpy.ops.bim.assign_class(obj=obj.name, ifc_class="IfcGrid") grid = tool.Ifc.get_entity(obj) - collection = obj.BIMObjectProperties.collection or collection - - axes_collection = bpy.data.collections.new("UAxes") - collection.children.link(axes_collection) for i in range(0, self.total_u): verts = [ Vector((-2, i * self.u_spacing, 0)), @@ -57,19 +43,13 @@ def add_object(self, context): tag = chr(ord("A") + i) obj = bpy.data.objects.new(f"IfcGridAxis/{tag}", mesh) - axes_collection.objects.link(obj) - result = ifcopenshell.api.run( - "grid.create_grid_axis", - tool.Ifc.get(), - **{"axis_tag": tag, "uvw_axes": "UAxes", "grid": grid}, + "grid.create_grid_axis", tool.Ifc.get(), axis_tag=tag, uvw_axes="UAxes", grid=grid ) tool.Ifc.link(result, obj) - ifcopenshell.api.run("grid.create_axis_curve", tool.Ifc.get(), **{"axis_curve": obj, "grid_axis": result}) - obj.BIMObjectProperties.ifc_definition_id = result.id() + ifcopenshell.api.run("grid.create_axis_curve", tool.Ifc.get(), axis_curve=obj, grid_axis=result) + tool.Collector.assign(obj) - axes_collection = bpy.data.collections.new("VAxes") - collection.children.link(axes_collection) for i in range(0, self.total_v): verts = [ Vector((i * self.v_spacing, -2, 0)), @@ -82,16 +62,12 @@ def add_object(self, context): tag = str(i + 1).zfill(2) obj = bpy.data.objects.new(f"IfcGridAxis/{tag}", mesh) - axes_collection.objects.link(obj) - result = ifcopenshell.api.run( - "grid.create_grid_axis", - tool.Ifc.get(), - **{"axis_tag": tag, "uvw_axes": "VAxes", "grid": grid}, + "grid.create_grid_axis", tool.Ifc.get(), axis_tag=tag, uvw_axes="VAxes", grid=grid ) tool.Ifc.link(result, obj) - ifcopenshell.api.run("grid.create_axis_curve", tool.Ifc.get(), **{"axis_curve": obj, "grid_axis": result}) - obj.BIMObjectProperties.ifc_definition_id = result.id() + ifcopenshell.api.run("grid.create_axis_curve", tool.Ifc.get(), axis_curve=obj, grid_axis=result) + tool.Collector.assign(obj) class BIM_OT_add_object(Operator, tool.Ifc.Operator):