wrong result in bpy.context.mode (*Postponed until after 2.63*) #30911

Closed
opened 2012-04-11 19:34:27 +02:00 by Krantz Geoffroy · 8 comments

%%%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.%%%

%%%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.%%%
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

%%%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'}:

%%%

%%%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?%%%

%%%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?%%%
Author
Member

%%%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.
%%%

%%%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 :)%%%

%%%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 :)%%%
Author
Member

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

%%%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.%%%

%%%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.%%%

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#30911
No description provided.