[Maya] Converting an Expanded List back to Range Format?

Alot of people ask how to take a Range and Expand it, but I would to do the reverse - take a long list of components and convert them back to Range.

Is there a method to do this? I tried LS and FILTEREXPAND, but once a list is expanded, its always returned expanded.

I would either use a function that converted a sequence of numbers into ranges, or you can use cmds.polyListComponentConversion. The downside being that it only works on polygon components and you have to know the component type.

flat = cmds.ls(sl=True, fl=True)
print flat
range = cmds.polyListComponentConversion(flat, fv=True, tv=True)
print range

# [u'cube.vtx[34]', u'cube.vtx[35]', u'cube.vtx[36]', u'cube.vtx[41]']
# [u'cube.vtx[34:36]', u'cube.vtx[41]']

This operation is a sin against nature and should be illegal

haha ok!

I think it’s viable for displaying information about sequences/selection, but don’t know what application it would have in Maya. In any case I would do it as a sequence-to-range python conversion, not using methods in maya.