implementation of #3332

This commit is contained in:
Bruno Perdigão
2023-07-06 18:04:57 -03:00
parent 02bca5a622
commit a4c90d8b53
3 changed files with 23 additions and 4 deletions
@@ -142,8 +142,13 @@ class RemoveArray(bpy.types.Operator, tool.Ifc.Operator):
bl_label = "Remove Array"
bl_options = {"REGISTER", "UNDO"}
item: bpy.props.IntProperty()
total_items: bpy.props.IntProperty()
keep_objs: bpy.props.BoolProperty(name="Keep Objects", default=False)
def _execute(self, context):
if (self.keep_objs) & (self.item < (self.total_items - 1)):
self.report({"INFO"}, "Keeping the objects is only allowed when you are removing the last Array of the object")
return {"FINISHED"}
obj = context.active_object
element = tool.Ifc.get_entity(obj)
props = obj.BIMArrayProperties
@@ -159,7 +164,7 @@ class RemoveArray(bpy.types.Operator, tool.Ifc.Operator):
except:
return {"FINISHED"}
tool.Model.regenerate_array(parent, data)
tool.Model.regenerate_array(parent, data, self.keep_objs)
pset = tool.Ifc.get().by_id(pset["id"])
if len(data) == 1:
@@ -171,6 +176,13 @@ class RemoveArray(bpy.types.Operator, tool.Ifc.Operator):
return {"FINISHED"}
def draw(self, context):
row = self.layout.row()
row.prop(self, "keep_objs")
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
class SelectArrayParent(bpy.types.Operator):
bl_idname = "bim.select_array_parent"
@@ -219,7 +219,9 @@ class BIM_PT_array(bpy.types.Panel):
name = f"{array['count']} Items ({array.get('method', 'OFFSET').capitalize()})"
row.label(text=name, icon="MOD_ARRAY")
row.operator("bim.enable_editing_array", icon="GREASEPENCIL", text="").item = i
row.operator("bim.remove_array", icon="X", text="").item = i
op = row.operator("bim.remove_array", icon="X", text="")
op.item = i
op.total_items = len(ArrayData.data["parameters"]["data_dict"])
row = box.row(align=True)
icon = "EMPTY_ARROWS" if array.get("use_local_space", False) else "EMPTY_AXIS"
row.label(text=f"X: {array['x']}", icon=icon)
+7 -2
View File
@@ -531,7 +531,7 @@ class Model(blenderbim.core.tool.Model):
return axes
@classmethod
def regenerate_array(cls, parent, data):
def regenerate_array(cls, parent, data, keep_objs=False):
unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get())
obj_stack = [parent]
@@ -601,7 +601,12 @@ class Model(blenderbim.core.tool.Model):
element = tool.Ifc.get().by_guid(removed_child)
obj = tool.Ifc.get_object(element)
if obj:
tool.Geometry.delete_ifc_object(obj)
if keep_objs:
pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array")
pset = tool.Ifc.get().by_id(pset["id"])
ifcopenshell.api.run("pset.remove_pset", tool.Ifc.get(), product=element, pset=pset)
else:
tool.Geometry.delete_ifc_object(obj)
bpy.context.view_layer.update()