From c40cc3f7406400bb70da58524f1ad7a6c0902596 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 19 Sep 2023 11:47:43 +0500 Subject: [PATCH] select array parent / all array objects to work without parent guid argument now it's getting parent guid from the currently active object, not from provided guid argument - so now it's possible to add those operators to quick favorites --- .../blenderbim/bim/module/model/array.py | 45 +++++++++++++++---- .../blenderbim/bim/module/model/ui.py | 6 +-- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/array.py b/src/blenderbim/blenderbim/bim/module/model/array.py index 5b1606154b..087bf1e436 100644 --- a/src/blenderbim/blenderbim/bim/module/model/array.py +++ b/src/blenderbim/blenderbim/bim/module/model/array.py @@ -206,15 +206,29 @@ class SelectArrayParent(bpy.types.Operator): bl_idname = "bim.select_array_parent" bl_label = "Select Array Parent" bl_options = {"REGISTER", "UNDO"} - parent: bpy.props.StringProperty(description="Parent Element GUID") + + @classmethod + def poll(cls, context): + if not context.active_object: + cls.poll_message_set("No active object selected") + return False + return True def execute(self, context): - try: - element = tool.Ifc.get().by_guid(self.parent) - except: - self.report({"ERROR"}, f"Couldn't find array parent by guid '{self.parent}'") + object = context.active_object + element = tool.Ifc.get_entity(object) + array_pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array") + if not array_pset: + self.report({"ERROR"}, f"Object is not part of an array.") return {"CANCELLED"} - obj = tool.Ifc.get_object(element) + + try: + parent_element = tool.Ifc.get().by_guid(array_pset["Parent"]) + except: + self.report({"ERROR"}, f"Couldn't find array parent by guid '{array_pset['Parent']}'") + return {"CANCELLED"} + + obj = tool.Ifc.get_object(parent_element) if obj: tool.Blender.select_and_activate_single_object(context, active_object=obj) return {"FINISHED"} @@ -224,13 +238,26 @@ class SelectAllArrayObjects(bpy.types.Operator): bl_idname = "bim.select_all_array_objects" bl_label = "Select All Array Objects" bl_options = {"REGISTER", "UNDO"} - parent: bpy.props.StringProperty(description="Parent Element GUID") + + @classmethod + def poll(cls, context): + if not context.active_object: + cls.poll_message_set("No active object selected") + return False + return True def execute(self, context): + object = context.active_object + element = tool.Ifc.get_entity(object) + array_pset = ifcopenshell.util.element.get_pset(element, "BBIM_Array") + if not array_pset: + self.report({"ERROR"}, f"Object is not part of an array.") + return {"CANCELLED"} + try: - parent_element = tool.Ifc.get().by_guid(self.parent) + parent_element = tool.Ifc.get().by_guid(array_pset["Parent"]) except RuntimeError: - self.report({"ERROR"}, f"Couldn't find array parent by guid '{self.parent}'") + self.report({"ERROR"}, f"Couldn't find array parent by guid '{array_pset['Parent']}'") return {"CANCELLED"} array_objects = tool.Blender.Modifier.Array.get_all_objects(parent_element) diff --git a/src/blenderbim/blenderbim/bim/module/model/ui.py b/src/blenderbim/blenderbim/bim/module/model/ui.py index 6a0b8005f8..07cd3ec4bd 100644 --- a/src/blenderbim/blenderbim/bim/module/model/ui.py +++ b/src/blenderbim/blenderbim/bim/module/model/ui.py @@ -188,10 +188,8 @@ class BIM_PT_array(bpy.types.Panel): if ArrayData.data["parameters"]: row = self.layout.row(align=True) row.label(text=ArrayData.data["parameters"]["parent_name"], icon="CON_CHILDOF") - op = row.operator("bim.select_array_parent", icon="OBJECT_DATA", text="") - op.parent = ArrayData.data["parameters"]["Parent"] - op = row.operator("bim.select_all_array_objects", icon="RESTRICT_SELECT_OFF", text="") - op.parent = ArrayData.data["parameters"]["Parent"] + row.operator("bim.select_array_parent", icon="OBJECT_DATA", text="") + row.operator("bim.select_all_array_objects", icon="RESTRICT_SELECT_OFF", text="") if ArrayData.data["parameters"]["data_dict"]: row.operator("bim.add_array", icon="ADD", text="")