how to use vert order in 2.5

i just saw that there is in vert menu a vert order function

so i guess there must be a way to use this function and i need this one
for a script

anybody knows an example for this ?

thanks happy 2.5

Crouch have a script called index visualizer that shows vertex indexes. Maybe that can help.

not verts indexe

there is a command in menu for mesh vert which can re order or sort the vert list
that’s the one i’m referring here but done in a script!

thanks happy 2.5

I meant that Crouch visualizer allows you to see what vertex sort does. But I dont know how to reorder the mesh.
Vertices has an index property and i saw some algorithm for convex hulls somewhere thats can help you to sort them.

Those consist in finding the left-bottom most vertex and then look for left-mid, left-top and so on until you reach the right-top vertex.

did you see the command inmen u mesh for vert
that’s the one which is dong the sort on anymesh
but what’s the API counterpart for it!

i’m trying to make an algo for sorting verts in a simple loine
and that’s not an easy one

with this command it would be very easy to do and faster i guess

thnaks happy 2.5

The python command should be in the tooltip. If I found the right command, it’s bpy.ops.mesh.vertices_sort().

tried with something like this on selected object
bpy.context.scene.objects.active = bpy.context.scene.objects[“Softbox”]

bpy.ops.mesh.vertices_sort()

bpy.ops.object.editmode_toggle()

but still gives me an error there must also be a way to select some vertices or all of them and do a sort

i used an open line mesh to test this

Vertex Sort
As far as I know, the Vertex Sort command sorts the vertices as they appear on the screen from left to right. See the screen shot below, this uses Crouch’s index visualiser to show how the sort effects the indices.



On the left are the indices assigned to vertices when a cube is first created. On the right are the indices after the sort has been run on all the vertices, notice that the vertex index increases from left to right.

Determining Vertex Order
If you have a line of mesh vertices connected by edges and you need the vertex order along the line, then you need the command

bpy.data.meshes["Line"].edge_loops_from_edges()

Suppose you have an object which contains a line of mesh vertices connected by edges, then you can use the command as follows.

import bpy

# Get the line object
ob = bpy.context.active_object
me = ob.data

# Store the edge data for the line mesh
ed = me.edges

# Store the edges loops for all the edges.
# This is a list of vertices in order along the line.
# If the mesh is not a simple line, there will be more than one edge loop.
loops = me.edge_loops_from_edges(ed)
print(loops)

Hope this is the kind of thing you are looking for.
Cheers,
Truman

[ATTACH=CONFIG]134835[/ATTACH]2 things

1-

when you simply say ed=me.edge

does this really make s new list or simply refer back to the original list of edges?

2 - sort

when you say sorted is the list sorted or you just show the vert in sorted order

i need to create a new list of vert in sorted order from beginning of line to the end of the line

now i can find the first and last point that’s easy
but then need to find next vert in line

i 'll try to explain more the concept here
problem sometimes is that a mesh line does not guarantie that the verts are in order from left to right
so the need to make a new ordered list of vert from beginning to end of line

so i tough the sort vert command might do the trick here
but never use that one before so not certain how to apply this one!

i need to go from a mesh line with no order inv ert list from left ro right

to an ordered list of vert
see pic
first line is ordered and second line right is not which is the orginal mesh lline

i tought ounce a mesh is created you cannot change the data for verts
or could cause problem it would be easier to rebuilt the mesh from scratch

you can edit an exsiting mesh data to add more verts ( or faces but not yet i think )
but theses are appended at the end of the vert list in mesh

i’ll experiment more with this


 
 import bpy
 
 
# Get the line object
 
ob = bpy.context.active_object
me = ob.data
 
# Store the edge data for the line mesh
 
ed = me.edges
print('edges in sorted order = ',ed)
 
 
 
print ()
print ()
print ('^^^^^^^^^^^^^^^^ ')
print ()
 
edgeno=2
edge =me.edges[edgeno]
edgeVerts = edge.vertices[:]
 
#edgeVerts = myMesh.edges[edgeno].vertices[:]
print(' Edge s    verts =')
print ( 'edgeVerts = myMesh.edges[edgeno].vertices[:] ')
print()
print ( 'edge no =',edgeno,' myMesh.edges[edgeno].vertices[:] =', me.edges[edgeno].vertices[:] )
print()
print(' list of vert for selected  edge(',edgeno,')  =',edgeVerts)
print ()
 
 
print ()
print ('^^^^^^^^^^^^^^^^ ')
print ()
print('List of Vertex location for selected  edge  (  usually  only 2 verticies ) ')
print ()
coords = [me.vertices[a].co for a in edgeVerts]
 
print('Verts coordinates for selected edge( ',edgeno,') = coords=',  coords)
print ()
 
 
print ()
print ()
print ('^^^^^^^^^^^^^^^^ ')
print ()
 
# Store the list of vertices for a selected edge
 
# Create a list of the vertex locations
 
print ()
 
coords = [me.vertices[a].co for a in edgeVerts]
 
for e in me.edges:
# print ('e=',e.key)
# print (' vert index =', me.edges[e.key].vertices[:])
 print (' Edge index =',e.key)
 print('Verts coordinates for selected edge( ',e,') = coords=',  coords)
 jj=0
 for n in e.key:
#  print('jj=',jj,me.vertices[n].co,' vert index =', me.edges[jj].vertices[:])
  print('jj=',jj,me.vertices[n].co)
  jj+=1
  print()
 
 
# Store the edges loops for all the edges.
# This is a list of vertices in order along the line.
# If the mesh is not a simple line, there will be more than one edge loop.
 
loops = me.edge_loops_from_edges(ed)
print('Loop in sorted order = ',loops)
 
  
 

how do i get the index of edge with the edge loop and e
i can get vert index with e.key but how tog et the edge index?

The edge loop function in my last post returns a list of vertices in the correct order along the line. That is, the first index in the list is the first vertex, the second index is the second vertex etc. Here’s an example of a mesh where the vertex indices change, so does the output from the script.

Here is a screenshot showing the vertex indices in the line mesh


The output from the script is

[[0, 1, 5, 2, 3, 6, 4]]

which is precisely the order on the line.

Now suppose that the vertex indices change somehow and now look as follows,



The script output changes to,

[[6, 5, 4, 3, 2, 1, 0]]

which again is the order along the line.

Cheers,
Truman