All my object have their location at 0,0,0 I would prefer if they have their location in the center of the object.
I thought I could just select ht object, go into edit, snap the cursor to the center, go back to object mode and adjust the origin.
I always get the error context is incorrect for snap_cursor_to_center() but I am checking before that I am in the VIEW_3D. I am not sure what is meant by context error.
import bpy
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for object in bpy.data.objects[:1]: # only one for testing
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
object.select_set(state=True)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.view3d.snap_cursor_to_center() # ERROR :(
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
```
bpy.context.scene.objectsinstead ofbpy.data.objectsand use the python console to test, Cheers! – brockmann Apr 22 '20 at 12:54