Skip to content

Commit

Permalink
select array parent / all array objects to work without parent guid a…
Browse files Browse the repository at this point in the history
…rgument

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
  • Loading branch information
Andrej730 committed Sep 19, 2023
1 parent 5604095 commit c40cc3f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
41 changes: 34 additions & 7 deletions src/blenderbim/blenderbim/bim/module/model/array.py
Expand Up @@ -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):
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:
element = tool.Ifc.get().by_guid(self.parent)
parent_element = tool.Ifc.get().by_guid(array_pset["Parent"])
except:
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"}
obj = tool.Ifc.get_object(element)

obj = tool.Ifc.get_object(parent_element)
if obj:
tool.Blender.select_and_activate_single_object(context, active_object=obj)
return {"FINISHED"}
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/blenderbim/blenderbim/bim/module/model/ui.py
Expand Up @@ -188,10 +188,8 @@ def draw(self, context):
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="")
Expand Down

0 comments on commit c40cc3f

Please sign in to comment.