From 097c5cee3cdaffe68916ab8e8346ad41612a4b4b Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Tue, 28 May 2024 21:17:23 -0500 Subject: [PATCH] fix #3802 - Copy array attributes from another array. Big thank you to @brunoperdigao, for the help! --- .../blenderbim/bim/module/model/array.py | 17 +++++++++++++- .../blenderbim/bim/module/model/prop.py | 23 +++++++++++++++++++ .../blenderbim/bim/module/model/ui.py | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/array.py b/src/blenderbim/blenderbim/bim/module/model/array.py index 8da6dfb74e..a521ee500b 100644 --- a/src/blenderbim/blenderbim/bim/module/model/array.py +++ b/src/blenderbim/blenderbim/bim/module/model/array.py @@ -83,8 +83,17 @@ class EnableEditingArray(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = context.active_object element = tool.Ifc.get_entity(obj) - data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Array", "Data"))[self.item] props = obj.BIMArrayProperties + + relating_obj = props.relating_array_object + + if relating_obj: + element = tool.Ifc.get_entity(relating_obj) + parent_globalid = ifcopenshell.util.element.get_pset(element, "BBIM_Array", "Parent") + parent_element = tool.Ifc.get().by_guid(parent_globalid) + data = json.loads(ifcopenshell.util.element.get_pset(parent_element, "BBIM_Array", "Data"))[self.item] + else: + data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Array", "Data"))[self.item] props.count = data["count"] si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) props.x = data["x"] * si_conversion @@ -93,7 +102,9 @@ class EnableEditingArray(bpy.types.Operator, tool.Ifc.Operator): props.use_local_space = data.get("use_local_space", False) props.sync_children = data.get("sync_children", False) props.method = data.get("method", "OFFSET") + props.is_editing = self.item + return {"FINISHED"} @@ -137,6 +148,10 @@ class EditArray(bpy.types.Operator, tool.Ifc.Operator): tool.Blender.Modifier.Array.set_children_lock_state(element, self.item, True) tool.Blender.Modifier.Array.constrain_children_to_parent(element) + + #clears the relating_array_object so it doesn't show again next time + props.relating_array_object = None + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/model/prop.py b/src/blenderbim/blenderbim/bim/module/model/prop.py index 3b55cc945b..96f375fa1a 100644 --- a/src/blenderbim/blenderbim/bim/module/model/prop.py +++ b/src/blenderbim/blenderbim/bim/module/model/prop.py @@ -87,6 +87,21 @@ def update_type_page(self, context): AuthoringData.data["paginated_relating_types"] = AuthoringData.paginated_relating_types() +def update_relating_array_from_object(self, context): + bpy.ops.bim.enable_editing_array(item=self.is_editing) + return + + +def is_object_array_applicable(self, obj): + element = tool.Ifc.get_entity(obj) + if not element: + return False + return ifcopenshell.util.element.get_pset(element, "BBIM_Array") + + + + + class BIMModelProperties(PropertyGroup): ifc_class: bpy.props.EnumProperty(items=get_ifc_class, name="Construction Class", update=update_ifc_class) relating_type_id: bpy.props.EnumProperty( @@ -203,6 +218,14 @@ class BIMArrayProperties(PropertyGroup): description="Regenerate all children based on the parent object", default=False, ) + relating_array_object: bpy.props.PointerProperty( + type=bpy.types.Object, + name="Copy Array Properties", + update=update_relating_array_from_object, + poll=is_object_array_applicable, + ) + + class BIMStairProperties(PropertyGroup): diff --git a/src/blenderbim/blenderbim/bim/module/model/ui.py b/src/blenderbim/blenderbim/bim/module/model/ui.py index 0ad66da688..01727e6887 100644 --- a/src/blenderbim/blenderbim/bim/module/model/ui.py +++ b/src/blenderbim/blenderbim/bim/module/model/ui.py @@ -223,6 +223,8 @@ class BIM_PT_array(bpy.types.Panel): row = col.row(align=True) row.prop(props, "z") row.operator("bim.input_cursor_z_array", icon="CURSOR", text="") + row = col.row(align=True) + row.prop(props, "relating_array_object", icon="COPYDOWN") else: row = box.row(align=True) name = f"{array['count']} Items ({array.get('method', 'OFFSET').capitalize()})"