I'm writing a script to create a cubical object out of several joined planes. After joining the meshes into one object (shadow_catcher), I need to set its origin to center of mass, so I call the following commands:

enter image description here

bpy.ops.object = bpy.data.objects["shadow_catcher"]
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='MEDIAN')

However, I get the following error:

AttributeError: 'Object' object has no attribute 'origin_set'

Strangely, this operation does work using the GUI. I have been searching for a solution for hours but alas no luck.. Any help would be greatly appreciated!


1 Answer 1


In your first line, you need set the active object, not bpy.ops.object. You also need to select the object.

bpy.context.view_layer.objects.active = bpy.data.objects["shadow_catcher"]
bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS', center='MEDIAN')
  • $\begingroup$ Works! Thank you $\endgroup$
    – Tal Taiber
    Jun 1, 2022 at 21:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .