def ob_copy_and_parent(ob: Object, parents: Iterable[Object]) -> None: is_orig = True space_data = bpy.context.space_data use_local_view = bool(space_data.local_view) for parent in parents: if is_orig: ob_copy = ob is_orig = False else: ob_copy = ob.copy() for coll in parent.users_collection: coll.objects.link(ob_copy) if use_local_view: ob_copy.local_view_set(space_data, True) ob_copy.select_set(True) ob.location = parent.location ob.rotation_euler = parent.rotation_euler ob.parent = parent ob.matrix_parent_inverse = parent.matrix_basis.inverted()
def parent_object_to(self, child: Object, parent: Object): child.parent = parent