So with a given mesh, I want to select the longest edge loop on the object. How do I do that with Python in Maya?
pseudocode:
open_edges = get all the edges in a queue
edge_lenths = dictionary (length > list of edges)
while len(open_edges) > 1:
get first edge with pop
convert edge to edge loop
measure loop.
edge_lenghts[measure] = edges in the loop
remove all edges in loop from open_edges
repeat
length_in_order = edge_lengths.keys()
length_in_order.sort()
longest loop = edge_lengths[length_in_order[-1]]
you cant do it with a vanilla for-loop because the collection will be changing as you go. You could also make a dirty list and add edges to that as you use them in an edge loop, then ignore them as you work up the list.
I’m not sure the code will actually achieve what I want. First off, it doesn’t seem to do any path finding to see if the edges are even connected to one another. Secondly, not all edges are supposed to be considered in each edge loop as it needs to follow a certain direction.
[QUOTE=Theodox;18357]pseudocode:
open_edges = get all the edges in a queue
edge_lenths = dictionary (length > list of edges)
while len(open_edges) > 1:
get first edge with pop
convert edge to edge loop
measure loop.
edge_lenghts[measure] = edges in the loop
remove all edges in loop from open_edges
repeat
length_in_order = edge_lengths.keys()
length_in_order.sort()
longest loop = edge_lengths[length_in_order[-1]]
you cant do it with a vanilla for-loop because the collection will be changing as you go. You could also make a dirty list and add edges to that as you use them in an edge loop, then ignore them as you work up the list.[/QUOTE]
You’ll have to convert each edge to an edge loop (i’m assuming you mean subdivision style edge loops) using cmds.polySelectSp(loop=True). Each edge can only belong to one loop, so much of the work is making sure you don’t do this twice for edges you’ve already looked at.
The code does not include direction, since ‘direction’ has no clear meaning in this context. You’d get lengths by looking at every edge in the loop and measuring the distance between start and end point. You’d be getting them in random order but for the use you described it would not matter – the distances will be added up in any case.
If you want to traverse edges one at a time that’s more work - I would not bother unless you needed to do something with the order info such as drawing a curve along the loop.