From 496ba6f22d869be2d8cb87ecfde15029b3f9adab Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Mon, 13 May 2024 14:01:11 -0500 Subject: [PATCH] fix #3802 - Copy array attributes from another array --- .../blenderbim/bim/module/model/array.py | 37 ++++++++++++---- .../blenderbim/bim/module/model/prop.py | 43 +++++++++++++++++++ .../blenderbim/bim/module/model/ui.py | 2 + 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/array.py b/src/blenderbim/blenderbim/bim/module/model/array.py index 4e51931479..2475bf3208 100644 --- a/src/blenderbim/blenderbim/bim/module/model/array.py +++ b/src/blenderbim/blenderbim/bim/module/model/array.py @@ -83,17 +83,32 @@ 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 - props.count = data["count"] - si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) - props.x = data["x"] * si_conversion - props.y = data["y"] * si_conversion - props.z = data["z"] * si_conversion - props.use_local_space = data.get("use_local_space", False) - props.sync_children = data.get("sync_children", False) - props.method = data.get("method", "OFFSET") + + relating_obj = props.relating_array_object + + if relating_obj: + relating_props = relating_obj.BIMArrayProperties + + props.count = relating_props.count + props.x = relating_props.x + props.y = relating_props.y + props.z = relating_props.z + props.use_local_space = relating_props.use_local_space + props.sync_children = relating_props.sync_children + props.method = relating_props.method + else: + data = json.loads(ifcopenshell.util.element.get_pset(element, "BBIM_Array", "Data"))[self.item] + si_conversion = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) + props.x = data["x"] * si_conversion + props.y = data["y"] * si_conversion + props.z = data["z"] * si_conversion + 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 +152,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 81f763068f..00f695b0e7 100644 --- a/src/blenderbim/blenderbim/bim/module/model/prop.py +++ b/src/blenderbim/blenderbim/bim/module/model/prop.py @@ -87,6 +87,41 @@ def update_type_page(self, context): AuthoringData.data["paginated_relating_types"] = AuthoringData.paginated_relating_types() +def update_relating_array_from_object(self, context): + if self.relating_array_object is None: + return + element = tool.Ifc.get_entity(self.relating_array_object) + if not element: + return + # If a child is selected, the following assigns the parent to the relating_array_object + parent_globalid = element.IsDefinedBy[0].RelatingPropertyDefinition.HasProperties[0].NominalValue.wrappedValue + parent_element = tool.Ifc.get().by_guid(parent_globalid) + parent_of_relating_array_object = tool.Ifc.get_object(parent_element) + #The following error handling is used to break out when an array parent is selected + try: + element.IsDefinedBy[0].RelatingPropertyDefinition.HasProperties[1].NominalValue.wrappedValue + except AttributeError: + pass + else: + bpy.ops.bim.enable_editing_array(item=self.is_editing) + return + + self.relating_array_object = parent_of_relating_array_object + bpy.ops.bim.enable_editing_array(item=self.is_editing) + + return self.relating_array_object + + +def is_object_array_applicable(self, obj): + element = tool.Ifc.get_entity(obj) + if not element: + return False + return element.IsDefinedBy[0].RelatingPropertyDefinition.Name == "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 +238,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()})"