From 04172a87cbc87b2fe2247b4f4fff3eed39e2e2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Tue, 30 Apr 2024 17:50:31 -0300 Subject: [PATCH 1/2] when bpy.ops.bim.object_duplicate_move_linked_aggregate is called from the panel, the new objects are placed based on the 3d cursor position --- .../blenderbim/bim/module/aggregate/ui.py | 1 + .../blenderbim/bim/module/geometry/operator.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py index e7b47eefc3..4a6c3c4ae0 100644 --- a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py +++ b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py @@ -145,6 +145,7 @@ class BIM_PT_linked_aggregate(Panel): else: row.label(text=f"{Number_Linked_Aggregates} Linked Aggregates") op = row.operator("bim.object_duplicate_move_linked_aggregate", text="", icon="DUPLICATE") + op.location_from_3d_cursor = True if type(Number_Linked_Aggregates) is int: if Number_Linked_Aggregates > 0: op = row.operator("bim.select_linked_aggregates", text="", icon="OUTLINER_DATA_POINTCLOUD") diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index f953c1d743..f2ac8ddcd4 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -947,6 +947,7 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator): bl_label = "IFC Duplicate Linked Aggregate" bl_options = {"REGISTER", "UNDO"} is_interactive: bpy.props.BoolProperty(name="Is Interactive", default=True) + location_from_3d_cursor: bpy.props.BoolProperty(name="Position Duplicate Based on 3d cursor", default=False) @classmethod def poll(cls, context): @@ -1073,7 +1074,19 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator): if "BBIM_Linked_Aggregate" in r.RelatingGroup.Name ] tool.Ifc.run("group.assign_group", group=linked_aggregate_group[0], products=new) - + + def get_location_from_3d_cursor(old_to_new): + for new in old_to_new.values(): + aggregate = ifcopenshell.util.element.get_aggregate(new[0]) + if aggregate: + base_obj = tool.Ifc.get_object(aggregate) + base_obj_location = base_obj.location.copy() + break + + for new in old_to_new.values(): + new_obj = tool.Ifc.get_object(new[0]) + location_diff = new_obj.location - base_obj_location + new_obj.location = context.scene.cursor.location + location_diff if len(context.selected_objects) != 1: return {"FINISHED"} @@ -1101,6 +1114,9 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator): custom_incremental_naming_for_element_assembly(old_to_new) + if self.location_from_3d_cursor: + get_location_from_3d_cursor(old_to_new) + blenderbim.bim.handler.refresh_ui_data() return old_to_new From 66e829a8aa3032a2d4f79adb1ae2eed37033ed6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Tue, 7 May 2024 20:56:12 -0300 Subject: [PATCH 2/2] - Fix the basepoint to be the parent aggregate. - Change the way that "location_to_cursor_3d" is called. - Create a new operator to use in the ui. --- .../blenderbim/bim/module/aggregate/ui.py | 3 +- .../bim/module/geometry/__init__.py | 1 + .../bim/module/geometry/operator.py | 38 ++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py index 4a6c3c4ae0..f15b0df8d8 100644 --- a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py +++ b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py @@ -144,8 +144,7 @@ class BIM_PT_linked_aggregate(Panel): row.label(text="Not a Linked Aggregate") else: row.label(text=f"{Number_Linked_Aggregates} Linked Aggregates") - op = row.operator("bim.object_duplicate_move_linked_aggregate", text="", icon="DUPLICATE") - op.location_from_3d_cursor = True + op = row.operator("bim.duplicate_linked_aggregate_to_3d_cursor", text="", icon="DUPLICATE") if type(Number_Linked_Aggregates) is int: if Number_Linked_Aggregates > 0: op = row.operator("bim.select_linked_aggregates", text="", icon="OUTLINER_DATA_POINTCLOUD") diff --git a/src/blenderbim/blenderbim/bim/module/geometry/__init__.py b/src/blenderbim/blenderbim/bim/module/geometry/__init__.py index 816718cb06..0bf808c2ef 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/__init__.py @@ -29,6 +29,7 @@ classes = ( operator.GetRepresentationIfcParameters, operator.DuplicateMoveLinkedAggregate, operator.DuplicateMoveLinkedAggregateMacro, + operator.DuplicateLinkedAggregateTo3dCursor, operator.OverrideDelete, operator.OverrideDuplicateMove, operator.OverrideDuplicateMoveLinked, diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index f2ac8ddcd4..a5839a6a9e 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -936,18 +936,17 @@ class OverrideDuplicateMoveLinked(bpy.types.Operator): class DuplicateMoveLinkedAggregateMacro(bpy.types.Macro): - bl_description = "Create a new linked aggregate" + bl_description = "Create and move a new linked aggregate" bl_idname = "bim.object_duplicate_move_linked_aggregate_macro" - bl_label = "IFC Duplicate Linked Aggregate" + bl_label = "IFC Duplicate and Move Linked Aggregate" bl_options = {"REGISTER", "UNDO"} class DuplicateMoveLinkedAggregate(bpy.types.Operator): bl_idname = "bim.object_duplicate_move_linked_aggregate" - bl_label = "IFC Duplicate Linked Aggregate" + bl_label = "IFC Duplicate and Move Linked Aggregate" bl_options = {"REGISTER", "UNDO"} is_interactive: bpy.props.BoolProperty(name="Is Interactive", default=True) - location_from_3d_cursor: bpy.props.BoolProperty(name="Position Duplicate Based on 3d cursor", default=False) @classmethod def poll(cls, context): @@ -960,7 +959,7 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator): return DuplicateMoveLinkedAggregate.execute_ifc_duplicate_linked_aggregate_operator(self, context) @staticmethod - def execute_ifc_duplicate_linked_aggregate_operator(self, context): + def execute_ifc_duplicate_linked_aggregate_operator(self, context, location_from_3d_cursor=False): self.new_active_obj = None self.group_name = "BBIM_Linked_Aggregate" self.pset_name = "BBIM_Linked_Aggregate" @@ -1075,13 +1074,9 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator): ] tool.Ifc.run("group.assign_group", group=linked_aggregate_group[0], products=new) - def get_location_from_3d_cursor(old_to_new): - for new in old_to_new.values(): - aggregate = ifcopenshell.util.element.get_aggregate(new[0]) - if aggregate: - base_obj = tool.Ifc.get_object(aggregate) - base_obj_location = base_obj.location.copy() - break + def get_location_from_3d_cursor(old_to_new, aggregate): + base_obj = tool.Ifc.get_object(aggregate) + base_obj_location = base_obj.location.copy() for new in old_to_new.values(): new_obj = tool.Ifc.get_object(new[0]) @@ -1114,14 +1109,29 @@ class DuplicateMoveLinkedAggregate(bpy.types.Operator): custom_incremental_naming_for_element_assembly(old_to_new) - if self.location_from_3d_cursor: - get_location_from_3d_cursor(old_to_new) + if location_from_3d_cursor: + get_location_from_3d_cursor(old_to_new, selected_element) blenderbim.bim.handler.refresh_ui_data() return old_to_new +class DuplicateLinkedAggregateTo3dCursor(bpy.types.Operator): + bl_idname = "bim.duplicate_linked_aggregate_to_3d_cursor" + bl_label = "IFC Duplicate Linked Aggregate to 3d Cursor" + bl_options = {"REGISTER", "UNDO"} + + @classmethod + def poll(cls, context): + return len(context.selected_objects) > 0 + + def execute(self, context): + return OverrideDuplicateMove.execute_duplicate_operator(self, context, linked=False) + + def _execute(self, context): + return DuplicateMoveLinkedAggregate.execute_ifc_duplicate_linked_aggregate_operator(self, context, location_from_3d_cursor=True) + class RefreshLinkedAggregate(bpy.types.Operator): bl_idname = "bim.refresh_linked_aggregate" bl_label = "IFC Refresh Linked Aggregate"