I'm having problem in working with various objects in blender. I'm writing a code to change the vertices of a object; but, it does not work when there are several objects at the scene, the problem is that I'm not getting change to the edit mode because of the "type" of the selection that I'm doing. When I select one object it do not necessary became the "master" object and so commands like bpy.ops.object.editmode_toggle() doesn't work.

I will put a photo to try to explain what a want to say with 'master' object enter image description here

even when I select the "Circle" and deselect the "Empty" object, the last one remains marked. If someone can help, I appreciate.

  • 1
    $\begingroup$ If you are using bpy ops commands, be aware that they work on the active object, not the selected one(s). The active object is usually the last object selected. $\endgroup$ Feb 13, 2022 at 21:53
  • $\begingroup$ I just tested this and it seems bpy.ops applies to the selected objects regardless of their active state. So you need to set the selection state of the objects using obj.select_set(False) (Blender 3.0) $\endgroup$
    – Dan
    Feb 16, 2022 at 2:24

1 Answer 1


Try setting the objects selection state. bpy.ops (in my brief testing) applies to whatever objects are selected, regardless of whether they are active...

Eg. Add an empty into a default scene with a cube...

import bpy

obj = bpy.context.active_object
bpy.ops.transform.translate(value=(-5, 0, 1))
#bpy.context.view_layer.objects.active = None

emObj = bpy.data.objects['Empty']
#bpy.context.view_layer.objects.active = emObj
bpy.ops.transform.translate(value=(3, 0, -1))

You must log in to answer this question.

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