# object set_origin not working

I have been looking at similar questions yet the following script is not returning any error but the origin of the object is not changed. What did I not set right? The context seems ok since I have selected and activated the object first:

imported_object = bpy.ops.import_scene.obj(filepath = the_file_path)
bpy.data.objects['Blob'].select = True

the_object = [ o for o in bpy.context.scene.objects if o.select ][0]
bpy.context.scene.objects.active = the_object

bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')


there is only one active and selected object which is 'Blob'. Here is a picture of the result:

Here is a link with the imported file : https://gist.github.com/compmonks/dd997dc53bb0dcd48de2fe077866266f

EDIT

This script is loaded with Blender on the command line so there is no direct access to context areas and so on. This causes some operators to not function properly. I found that loading blender with a blend file and the script was avoiding this problem. Not sure if this is the correct way to do so :

import os
os.system("THE_BLENDER_PATH THE_BLENDER_FILE.blend --python THE_PYTHON_SCRIPT.py")

• The active object is generally context.selected_objects[0] always context.active_object In your script above, if an object is imported named other than "Blob" the_object may or may not be "Blob". The set origin operator operates on all context.selected_objects. If you want to only set origin to geom on one object post export, deselect all, select one, make it active, call operator. – batFINGER Jul 19 '18 at 21:08
• Thanks for your answer. But even if another object was selected, no object is having its origin set to the geometry. The current context mode is OBJECT but I am wondering if this needs some kind of override – compmonks Jul 20 '18 at 13:25
• I edited the question with a picture. There is only the one mesh object returned as active and selected – compmonks Jul 20 '18 at 14:06
• If only one object in file, Code could be a two line script, the two operators. Can you provide a link to the obj file too please. – batFINGER Jul 20 '18 at 14:27
• just added a link in the question. The blender scene in which it is imported already contains objects. That's why I am making sure it is the only one selected and active first – compmonks Jul 20 '18 at 14:37