I wrote an operator to create an empty object and then make it a parent to the currently selected object. However, when I assign the parent object, the child object moves unless it is at the origin. How can I keep that from happening? Here is some code that demonstrates the problem:
class ObjectTest(bpy.types.Operator):
"""Tooltip"""
bl_idname = "myops.object_test"
bl_label = "Array of current object"
def execute(self,context):
origobj = bpy.context.active_object
bpy.context.scene.cursor.location = origobj.location
bpy.ops.object.empty_add()
objparent=bpy.context.active_object
objparent.name=origobj.name+"Array"
origobj.parent=objparent
return {'FINISHED'}
def register():
bpy.utils.register_class(ObjectTest)
def unregister():
bpy.utils.unregister_class(ObjectTest)
if __name__ == "__main__":
register()
I would like the empty parent object and the selected child object to be at the same location, not necessarily the origin. I am trying to make a group of objects that can be moved together, and a parent seems like the best way. I was using Blender 2.83, but I recently updated to 2.9. Thanks for your help.