Blender Version
Broken: Windows x64 builds of...
- 522bee3 - most recent 2.79 experimental
- f4dc9f9d68b - official 2.79b release
- all earlier versions at least as far back as 2.75a and possibly versions before this
Worked: unknown...
Short description of error
There are differing results when iterating through "select_history" when slicing is done with a negative index compared to when no slicing is done.
Exact steps for others to reproduce the error
- Open Blender
- Add a cube to the scene (if one is not already there).
- Change to edit mode and individually select any 5 of the cube's 6 faces
- Open Blender's Python Console and run these lines (or run the entire snippet from the text editor):
import bpy import bmesh bm = bmesh.from_edit_mesh(bpy.context.edit_object.data) bm.select_history for i, e in enumerate(bm.select_history): print(i, e) print() for i, e in enumerate(bm.select_history[:-2]): print(i, e)
The order of the elements from the first for loop iteration should differ from the second. The first gives you the faces in the order they were selected, the second does not.
Example output:
>>> for i, e in enumerate(bm.select_history): print(i, e) ... 0 <BMFace(0x00000188C3BF6388), index=3, totverts=4> 1 <BMFace(0x00000188C3BF65B8), index=13, totverts=4> 2 <BMFace(0x00000188C3BF63C0), index=4, totverts=4> 3 <BMFace(0x00000188C3BF6510), index=10, totverts=4> 4 <BMFace(0x00000188C3BF6698), index=17, totverts=4> >>> for i, e in enumerate(bm.select_history[:-2]): print(i, e) ... 0 <BMFace(0x00000188C3BF65B8), index=13, totverts=4> 1 <BMFace(0x00000188C3BF63C0), index=4, totverts=4> 2 <BMFace(0x00000188C3BF6510), index=10, totverts=4>
For the second for loop this is what I would have expected:
0 <BMFace(0x00000188C3BF6388), index=3, totverts=4> 1 <BMFace(0x00000188C3BF65B8), index=13, totverts=4> 2 <BMFace(0x00000188C3BF63C0), index=4, totverts=4>
This would match how slicing and/or reverse indexing works in regular Python:
>>> letters = ['a', 'b', 'c', 'e', 'f'] >>> letters[:-2] ['a', 'b', 'c']
Possible fix with D3197.