Creating grids now uses tool.Collector.assign instead of reimplementing collection management

This commit is contained in:
Dion Moult
2024-06-09 16:53:04 +10:00
parent 6e0665bd31
commit 177b8218ee
@@ -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):