- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
What Im trying to do is define "edge groups" from a edge selection based on which edges are connected to each other.
In the photo above, there would be 3 edge groups. The while loop in my code selects 1 edge and grows the selection to find the neighboring edge. If a neighboring edge is found, it adds it to the variable edgeCollection. This can be seen by uncommenting line 16. If a neighboring edge isnt found, it takes edgeCollection and sends it to edgeGroup. The while loop then repeats until no edges remain in the initial selection and edgeGroup ends up being a list containing edgeCollection lists.
Im using a for loop at the end of the script to check the information I built up in edgeGroup. I found that the First "edge group" from the image isnt passing over to edgeGroup or is being overwritten somehow and that the Third "edge group" is being doubled.
import maya.cmds as mc
import maya.mel as mel
def edgeGrouping():
edgeSelection = mc.ls(sl=1,fl=1)
print "Number of edges selected :",len(edgeSelection)
edgeGroups = []
edgeCollection = []
edgeCollection.append(edgeSelection[0])
edgeSelection.remove(edgeSelection[0])
while len(edgeSelection)+1 > 0:
#print edgeCollection
mc.select(edgeCollection[-1])
mel.eval('PolySelectTraverse 1')
edgeGrowth = mc.ls(sl=1)
mc.select(edgeSelection,d=1)
edgesToRemove = mc.ls(sl=1)
mc.select(edgeGrowth)
mc.select(edgesToRemove,d=1)
mc.select(edgeCollection,d=1)
nextEdge = mc.ls(sl=1)
if nextEdge:
edgeCollection.append(nextEdge[0])
edgeSelection.remove(nextEdge[0])
else:
edgeCollection = [x for x in edgeCollection]
edgeGroups.append(edgeCollection)
#print edgeCollection
#print edgeGroups
if len(edgeSelection) > 0:
edgeCollection *= 0
edgeCollection.append(edgeSelection[0])
edgeSelection.remove(edgeSelection[0])
else:
break
for i in range(len(edgeGroups)):
print "Edge Group :", i+1
for y in edgeGroups[i]:
print y
#mc.select(edgeGroups[0])
#print edgeGroups
edgeGrouping()
This is probably a logic error on my part some where in the code but I havent been able to figure it out and any help on it would be appreciated. Thanks in advance.
Solved! Go to Solution.