When I started to tidy up one of my models I came across an odd feature in Blender. You can only set the origin on the active object.
My main reason for setting an origin is to get all of the origins of all of the objects in a scene at the zero point. I find it easier to import in to other programmes and line them up if they all have the same centre.
Using the built in button, it is frustrating having to select one object at a time to set all the origins. I decided to create a script to do this for me.
Not as easy as I expected because even in code the set origin only works on the active object.
I just typed the lines in to the console to run it. After the last line press return one extra time to run it.
for item in bpy.context.scene.objects: if item.type == 'MESH': item.select = True bpy.context.scene.objects.active = item bpy.ops.object.origin_set(type='ORIGIN_CURSOR') item.select = False
The above worked in version 2.74 of Blender. It goes through ALL objects in the scene which is what I wanted.
for item in bpy.context.selected_objects: if item.type == 'MESH': bpy.context.scene.objects.active = item bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
In theory the above should work for the currently selected objects but I have not tested that script.
I came across another oversight when trying to copy that code to save it. To get the Windows Ctrl-C (copy) and Ctrl-V (paste) to work in the console window you first have to click on the console menu item at least once. After that Ctrl-C and Ctrl-V work as expected.