Array children now follow their parent with a "child-of" constraint #3492

This commit is contained in:
Gorgious
2023-07-23 13:38:37 +02:00
parent 41d6882b40
commit 1468b7fddd
2 changed files with 12 additions and 0 deletions
@@ -134,6 +134,8 @@ class EditArray(bpy.types.Operator, tool.Ifc.Operator):
pset = tool.Ifc.get().by_id(pset["id"])
data = json.dumps(data)
ifcopenshell.api.run("pset.edit_pset", tool.Ifc.get(), pset=pset, properties={"Data": data})
tool.Blender.Modifier.Array.constrain_children_to_parent(element)
return {"FINISHED"}
+10
View File
@@ -522,6 +522,16 @@ class Blender:
return cls.is_stair(element) or cls.is_door(element) or cls.is_window(element)
class Array:
@classmethod
def constrain_children_to_parent(cls, parent_element):
parent_obj = tool.Ifc.get_object(parent_element)
children = cls.get_all_children_objects(parent_element)
for child in children:
constraint = next(
(c for c in child.constraints if c.type == "CHILD_OF"), None
) or child.constraints.new("CHILD_OF")
constraint.target = parent_obj
@classmethod
def get_all_objects(cls, parent_element):
parent_obj = tool.Ifc.get_object(parent_element)