If I have an edge object, how can I get an edge loop with Python?
you can use this command to get edge loops…
Assuming you are running polySelect from a selection, you need a way to get the
int of the edge before running it.
Something like this?
import pymel.core body = pm.PyNode('BodyShape') selectedEdge = pm.selected().indices() # since you already have an object selected, passing the shape isn't necessary. But you can. pm.polySelect(body, edgeLoop=selectedEdge)
Thanks, will try this out. Might work (as well as polySelectSp()). But if possible I wish to avoid selection operations.
Also you can’t seem to pass a list to that flag, but this seems to work for multiple edge selections.
selectedEdges = [x.indices() for x in pm.selected(flatten=True)] [pm.polySelect(edgeLoop=edge, add=True) for edge in selectedEdges]
If you already know the index, then just pass the int directly to the flag. No selection required. (Edit: Oh yeah, I see what you mean by selections…)
I have an edge as a PyMel object, so I have an index.
pm.polySelect() selects an edge loop, I can handle this, but more preferred option would be to get edge loop as an object as well (list of pyMel edge objects) without selecting anything.
pm.polySelect() followed by
What do you mean by followed by?
import pymel.core as pm x = pm.polyPlane(n='grid') edges = x.edges edge = edges pm.polySelect(x, edgeLoop=edge.index())
The polySelect() selects the edge loop of “grid” edge number 111 in the viewport, while getting “grid” edge 111 do not require any selection.
import pymel.core as pm x = pm.polyPlane(n='grid') edges = x.edges edge = edges pm.polySelect(x, edgeLoop=edge.index()) loop = pm.selected(flatten=True)
I mean maybe there is alternative command to polySelect(), which allows to get edges without selection.
None that I’m aware of.
Sadly some operations in Maya involved mucking about in selections like that. I don’t really like having to do it either.
Your other option would be to recreate the edge loop detection algorithm yourself.
Ok, at current stage its working fine with selection.
Checked edge loop selection algorithm, should not be that hard to implement in Maya https://stackoverflow.com/questions/6999893/selecting-edge-loops
Issue is that I don`t need to select loop, I just use loops to detect necessary area of my geometry so in my case it would not be the best option.
Anyway, thanks for your support, Mr White! And other folks.
Based on previous replies I provided a not so elegant solution to your problem. I’m sure there are better ways of doing this, but here you go.
import pymel.core as pm x = pm.polyPlane(n='grid') edges = x.edges edge = edges loop = pm.polySelect(x, edgeLoop=edge.index(), ns=True) storeEdges =  for item in loop[::-1]: for edge in edges: edgeNum = edge.split("[").split("]") if item == long(edgeNum): storeEdges.append(edge)
This stores all the edges in the edge loop into the “storeEdges” list. You add the “ns” flag to make sure nothing is selected from polySelect and save the edge indexes in the variable “loop” and then loop through all of the meshes edges to find a match. You can probably do this by looping through the first edge’s connected edges, and then move on to the next connected edge to make it faster.