Tag Archives: code

selection in Blender

I’d wanted to select a certain mesh object and then edit it, but was getting weird errors, like:

RuntimeError: Operator bpy.ops.mesh.select_all.poll() failed, context is incorrect


RuntimeError: Operator bpy.ops.object.mode_set(mode='EDIT').poll() failed, context is incorrect

I couldn’t find my actual initial code, so here’s me trying to replicate it. All I’m doing is selecting the first cube.

my_object = bpy.context.scene.objects['Cube'] = True

>>> RuntimeError: Operator bpy.ops.mesh.select_all.poll() failed, context is incorrect

Turns out I needed to set the object as the active object and deselect any other object. If the originally selected object was in EDIT mode, I needed to toggle to OBJECT mode before toggling back EDIT mode. Otherwise, bpy.ops.object.mode_set(mode='EDIT') will appear finished but actually fail.

other_object = bpy.context.scene.objects['Cube.002'] = False

my_object = bpy.context.scene.objects['Cube'] = True = my_object




Hope this helps!

*My example snippet can replicate the select_all error, if the original object was in EDIT mode, but I can’t seem to reproduce the edit_mode error. However, I haven’t had any problems after deselecting all other objects and toggling to OBJECT mode before any further operations.

Blender 2.72