Detect Enter / Leave Edit Mode

Im writing a script for Blender v2.57b, and I need to be able to detect when the user enter or leave edit mode.

I search the API but couldn’t find anything else except:


or bpy.ops.object.mode_set

but there’s no bpy.ops.object.mode_get…

There’s always bpy.context.edit_object that return None or the Object that is currently edited, but is there a more “elegant” way to do this?

All I need to know is 1 or 0 if Im in edit mode or not, anybody?


look at the mode property of the context object

    obj = bpy.ocntext.object
    if obj:

i think you mean ‘context’ not ‘ocntext’

obj = bpy.context.object
if obj:

Your question in my (humble) opinion is wrong.

You want to know how to change edit and object mode for an object?

Suppose you have an ‘active’ object then you have (at least) three possibilities:
the toggle you found yourself

and an example (for my scripted tutorial)

def makeFace(v1,v2):
    obj = bpy.context.active_object
    bpy.ops.object.mode_set(mode='OBJECT')[v1].select = True[v2].select = True
    bpy.ops.object.editmode_toggle() #edit mode!

where you can see other possibilities