From 1d20f880536bdebc6b50a06c57db101552381dce Mon Sep 17 00:00:00 2001 From: Gorgious Date: Wed, 25 Aug 2021 12:29:44 +0200 Subject: [PATCH] Assign / Unassign Constraint executes on all selected objects --- .../bim/module/constraint/operator.py | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/constraint/operator.py b/src/blenderbim/blenderbim/bim/module/constraint/operator.py index d7b409fa93..567d49b266 100644 --- a/src/blenderbim/blenderbim/bim/module/constraint/operator.py +++ b/src/blenderbim/blenderbim/bim/module/constraint/operator.py @@ -187,17 +187,21 @@ class AssignConstraint(bpy.types.Operator): return IfcStore.execute_ifc_operator(self, context) def _execute(self, context): - obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object self.file = IfcStore.get_file() - ifcopenshell.api.run( - "constraint.assign_constraint", - self.file, - **{ - "product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id), - "constraint": self.file.by_id(self.constraint), - } - ) - Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id) + objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects + for obj in objs: + obj_id = obj.BIMObjectProperties.ifc_definition_id + if not obj_id: + continue + ifcopenshell.api.run( + "constraint.assign_constraint", + self.file, + **{ + "product": self.file.by_id(obj_id), + "constraint": self.file.by_id(self.constraint), + } + ) + Data.load(self.file, obj_id) return {"FINISHED"} @@ -212,15 +216,19 @@ class UnassignConstraint(bpy.types.Operator): return IfcStore.execute_ifc_operator(self, context) def _execute(self, context): - obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object self.file = IfcStore.get_file() - ifcopenshell.api.run( - "constraint.unassign_constraint", - self.file, - **{ - "product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id), - "constraint": self.file.by_id(self.constraint), - } - ) - Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id) + objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects + for obj in objs: + obj_id = obj.BIMObjectProperties.ifc_definition_id + if not obj_id: + continue + ifcopenshell.api.run( + "constraint.unassign_constraint", + self.file, + **{ + "product": self.file.by_id(obj_id), + "constraint": self.file.by_id(self.constraint), + } + ) + Data.load(self.file, obj_id) return {"FINISHED"}