# Change active selection from one object to another, with Python

I'm making a script to automate some steps I do quite often. In the script I need to change the active selection from one object to another to work on that object and then return the active selection to the first one, e.g. I have a cube and a circle, both separated objects, I do some things with the cube and then I have to select the circle to do some other operations, then when I'm done with that, I want to select the cube to keep working with it, thanks in advance.

• see if this helps blender.stackexchange.com/questions/44382/… – m.ardito Aug 19 '17 at 6:55
• That helps to select it, but I want to change the "active" property, so when you go bpy.context.active_object the object is now the second one. In other words I need to convert a secondary selection into the active and the active into the secondary, thanks for the reply nonetheless. – DeNapes Aug 19 '17 at 18:42

bpy.context.scene.objects.active

cube = bpy.data.objects['Cube']