When I added a new function of the Blender plugin, I learned how to get the selected order of vertices, edges, and faces of an object, so I will introduce it. Only the one selected by right-clicking (the default key layout is assumed hereafter) is targeted. You can select multiple vertices, edges, and faces at the same time with the B key, but you cannot get the selection order with Blender at this time.
The script to get the selection order for the currently selected object is shown below. Don't forget to import bmesh in addition to bpy to access the internal structure of blender. It includes version-dependent processing of blender, which is required from Blender 2.73. For more information, see [http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.73/Addons](http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.73] / Addons).
get_face_selection_sequence.py
import bpy
import bmesh #Needs additional import
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT') #Processing must be done in EDIT mode
bm = bmesh.from_edit_mesh(obj.data)
#Blender version is 2.Required when 73 or above
if bpy.app.version[0] >= 2 and bpy.app.version[1] >= 73:
bm.faces.ensure_lookup_table()
#Show face selection order
for e in bm.select_history:
if isinstance(e, bmesh.types.BMFace) and e.select:
print(repr(e))
get_edge_selection_sequence.py
import bpy
import bmesh #Needs additional import
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT') #Processing must be done in EDIT mode
bm = bmesh.from_edit_mesh(obj.data)
#Blender version is 2.Required when 73 or above
if bpy.app.version[0] >= 2 and bpy.app.version[1] >= 73:
bm.edges.ensure_lookup_table()
#Display the selection order of edges
for e in bm.select_history:
if isinstance(e, bmesh.types.BMEdge) and e.select:
print(repr(e))
get_vert_selection_sequence.py
import bpy
import bmesh #Needs additional import
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT') #Processing must be done in EDIT mode
bm = bmesh.from_edit_mesh(obj.data)
#Blender version is 2.Required when 73 or above
if bpy.app.version[0] >= 2 and bpy.app.version[1] >= 73:
bm.verts.ensure_lookup_table()
#Show the selection order of vertices
for e in bm.select_history:
if isinstance(e, bmesh.types.BMVert) and e.select:
print(repr(e))
The result of the execution is shown below.
result.py
>>> for e in bm.select_history:
... if isinstance(e, bmesh.types.BMFace) and e.select:
... print(repr(e))
<BMFace(0x108482cf0), index=4, totverts=4>
<BMFace(0x108482c80), index=2, totverts=4>
>>>
>>> for e in bm.select_history:
... if isinstance(e, bmesh.types.BMEdge) and e.select:
... print(repr(e))
<BMEdge(0x11241f380)>, index=11, verts=(0x10849a960/6, 0x10849a998/7)>
<BMEdge(0x11241f1a0)>, index=5, verts=(0x10849a880/2, 0x10849a8b8/3)>
>>>
>>> for e in bm.select_history:
... if isinstance(e, bmesh.types.BMVert) and e.select:
... print(repr(e))
<BMVert(0x10849a960), index=6>
<BMVert(0x10849a8f0), index=4>
>>>
Recommended Posts