diff --git a/src/blenderbim/blenderbim/bim/module/aggregate/operator.py b/src/blenderbim/blenderbim/bim/module/aggregate/operator.py index 9ab00d205c..d09179f6b1 100644 --- a/src/blenderbim/blenderbim/bim/module/aggregate/operator.py +++ b/src/blenderbim/blenderbim/bim/module/aggregate/operator.py @@ -40,21 +40,22 @@ class BIM_OT_assign_object(bpy.types.Operator, Operator): bl_label = "Assign Object" bl_options = {"REGISTER", "UNDO"} relating_object: bpy.props.IntProperty() - related_object: bpy.props.IntProperty() def _execute(self, context): + relating_obj = None + if self.relating_object: + relating_obj = tool.Ifc.get_object(tool.Ifc.get().by_id(self.relating_object)) + elif context.active_object: + relating_obj = context.active_object + if not relating_obj: + return + for obj in bpy.context.selected_objects: + if obj == relating_obj: + continue element = tool.Ifc.get_entity(obj) if not element: continue - if self.relating_object: - relating_obj = tool.Ifc.get_object(tool.Ifc.get().by_id(self.relating_object)) - else: - if obj == context.active_object: - continue - relating_obj = context.active_object - if not relating_obj: - continue result = core.assign_object( tool.Ifc, tool.Aggregate, @@ -65,8 +66,6 @@ class BIM_OT_assign_object(bpy.types.Operator, Operator): if not result: self.report({"ERROR"}, f" Cannot aggregate {obj.name} to {relating_obj.name}") - return {"FINISHED"} - class BIM_OT_unassign_object(bpy.types.Operator, Operator): """Remove aggregation relationship between two ifc elements""" @@ -164,10 +163,7 @@ class BIM_OT_add_aggregate(bpy.types.Operator, tool.Ifc.Operator): core.assign_object(tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=aggregate, related_obj=obj) def create_aggregate(self, context, ifc_class): - aggregate_collection = bpy.data.collections.new(f"{ifc_class}/Assembly") - context.scene.collection.children.link(aggregate_collection) aggregate = bpy.data.objects.new("Assembly", None) - aggregate_collection.objects.link(aggregate) bpy.ops.bim.assign_class(obj=aggregate.name, ifc_class=ifc_class) return aggregate diff --git a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py index d593599604..50bc8007f6 100644 --- a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py +++ b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py @@ -56,7 +56,6 @@ class BIM_PT_aggregate(Panel): if props.relating_object: op = row.operator("bim.assign_object", icon="CHECKMARK", text="") op.relating_object = props.relating_object.BIMObjectProperties.ifc_definition_id - op.related_object = context.active_object.BIMObjectProperties.ifc_definition_id row.operator("bim.disable_editing_aggregate", icon="CANCEL", text="") else: row = layout.row(align=True) diff --git a/src/blenderbim/test/bim/feature/aggregate.feature b/src/blenderbim/test/bim/feature/aggregate.feature index 0a2cca652f..662d3b6d15 100644 --- a/src/blenderbim/test/bim/feature/aggregate.feature +++ b/src/blenderbim/test/bim/feature/aggregate.feature @@ -18,10 +18,10 @@ Scenario: Disable editing aggregate Scenario: Assign object Given an empty IFC project And the object "IfcSite/My Site" is selected + And the object "IfcBuildingStorey/My Storey" is selected And I press "bim.enable_editing_aggregate" And the variable "relating_object" is "tool.Ifc.get().by_type('IfcSite')[0].id()" - And the variable "related_object" is "tool.Ifc.get().by_type('IfcBuildingStorey')[0].id()" - When I press "bim.assign_object(relating_object={relating_object}, related_object={related_object})" + When I press "bim.assign_object(relating_object={relating_object})" Then the object "IfcSite/My Site" is in the collection "IfcSite/My Site" And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" And the collection "IfcBuildingStorey/My Storey" is in the collection "IfcSite/My Site" @@ -31,8 +31,7 @@ Scenario: Unassign object And the object "IfcBuildingStorey/My Storey" is selected And I press "bim.enable_editing_aggregate" And the variable "relating_object" is "tool.Ifc.get().by_type('IfcSite')[0].id()" - And the variable "related_object" is "tool.Ifc.get().by_type('IfcBuildingStorey')[0].id()" - And I press "bim.assign_object(relating_object={relating_object}, related_object={related_object})" + And I press "bim.assign_object(relating_object={relating_object})" And the object "IfcBuildingStorey/My Storey" is selected When I press "bim.unassign_object" Then the object "IfcSite/My Site" is in the collection "IfcSite/My Site" diff --git a/src/blenderbim/test/bim/test_feature.py b/src/blenderbim/test/bim/test_feature.py index 20a48dd259..568bd48e13 100644 --- a/src/blenderbim/test/bim/test_feature.py +++ b/src/blenderbim/test/bim/test_feature.py @@ -18,6 +18,7 @@ import os import bpy +import traceback import webbrowser import ifcopenshell import blenderbim.tool as tool @@ -167,10 +168,14 @@ def i_add_a_plane_of_size_size_at_location(size, location): @when(parsers.parse('I press "{operator}"')) def i_press_operator(operator): operator = replace_variables(operator) - if "(" in operator: - exec(f"bpy.ops.{operator}") - else: - exec(f"bpy.ops.{operator}()") + try: + if "(" in operator: + exec(f"bpy.ops.{operator}") + else: + exec(f"bpy.ops.{operator}()") + except: + traceback.print_exc() + assert False, f"Failed to run operator bpy.ops.{operator}" @given(parsers.parse('I evaluate expression "{expression}"'))