Page MenuHome

wrong result in bpy.context.mode (*Postponed until after 2.63*)
Closed, InvalidPublic

Description

Hi,
in some case bpy.context.mode give bad result and use old variable name i think.
Result expected for in texture mode should be TEXTURE_PAINT but it's PAINT_TEXTURE, some for vertex paint and weight paint.
In blender/source/blender/makesrna/intern/rna_context.c, line 147 to 149, i've change in my build:
{CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
{CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
{CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
to
{CTX_MODE_PAINT_WEIGHT, "WEIGHT_PAINT", 0, "Weight Paint", ""},
{CTX_MODE_PAINT_VERTEX, "VERTEX_PAINT", 0, "Vertex Paint", ""},
{CTX_MODE_PAINT_TEXTURE, "TEXTURE_PAINT", 0, "Texture Paint", ""},
and it seem to work normaly.

Event Timeline

and in script/startup/bl_ui/space_view3d.py, line 46 to 55 change:
# Select Menu
if mode_string not in {'EDIT_TEXT', 'SCULPT', 'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE'}:
sub.menu("VIEW3D_MT_select_%s" % mode_string.lower())

if edit_object:
sub.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
elif obj:
if mode_string not in {'PAINT_TEXTURE'}:
sub.menu("VIEW3D_MT_%s" % mode_string.lower())
if mode_string in {'SCULPT', 'PAINT_VERTEX', 'PAINT_WEIGHT', 'PAINT_TEXTURE'}:

to:

# Select Menu
if mode_string not in {'EDIT_TEXT', 'SCULPT', 'WEIGHT_PAINT', 'VERTEX_PAINT', 'TEXTURE_PAINT'}:
sub.menu("VIEW3D_MT_select_%s" % mode_string.lower())

if edit_object:
sub.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
elif obj:
if mode_string not in {'TEXTURE_PAINT'}:
sub.menu("VIEW3D_MT_%s" % mode_string.lower())
if mode_string in {'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT'}:

asside from this being inconsistent, can you explain how this is a bug? - for eg, can this mis-match cause some error message or blender to fail on some operation?

For exemple you are in scultp or texture mode, you want to make something in object mode and come back in the first mode
cm = bpy.context.mode
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.mode_set(mode=cm, toggle=False)
for sculpt to object, it's work, but for texture mode it don't because cm equal 'PAINT_TEXTURE' and mode from bpy.ops.object.mode_set accepts only 'TEXTURE_PAINT'.
But it's the same probleme for vertex paint and weight paint.

I'd say it's not actually a bug, but more like mis-usage of api: you're getting mode from context and applying it on object. You need to get mode from active object, not context's mode.
Making this more consistent makes sense but i'd rather not do such changes before upcoming release.
Final word for Campbell :)

ok, i'll use the object's context.
Thanks

This context.mode is quite different from object.mode, for edit mode it can't match anyway, so don't think we should change it, better not even try to use it this way.

Brecht Van Lommel (brecht) changed the task status from Unknown Status to Invalid.May 3 2012, 6:15 PM