I have a PyMEL-function for converting a uv selection into a list containing each individual uv shell; it is a general-purpose function that I use for all sorts of things.
I have noticed that it’s not very fast though, so when there are too many uv shells around this function will stall - making other functions (further down the line) having to wait for it. Im hoping that maybe someone here on the forums could provide a little bit of feedback - maybe even a solution to this problem.
import pymel.core as pm
# Returns list with each shell in it
def convertToShell():
listFinal = []
# Store coords and check count
selCoords = pm.filterExpand(selectionMask=35) # Poly UV's
uvRemain = uvCount = len(selCoords)
# Progress window
pm.progressWindow(
isInterruptable=True,
maxValue=uvCount,
progress=0,
status="Pre-processing UV shells",
title="Pre-processing UV shells"
)
# Do for every shell
while uvRemain != 0:
# Break if cancelled by user
if pm.progressWindow(query=True, isCancelled=True) == True:
pm.warning("Interupted by user")
break
# Edit the progress window
pm.progressWindow(
edit=True,
progress=(uvCount - uvRemain),
status=("Pre-processing shells.
%s UVs left")%uvRemain
)
# Select the first and current coord of selCoords
pm.select(selCoords[0], replace=True)
# Expand selection to entire shell and store
pm.polySelectConstraint(type=0x0010, shell=True, border=False, mode=2)
pm.polySelectConstraint(shell=False, border=False, mode=0)
selShell = pm.ls(selection=True, flatten=True)
# Go back to original single-UV selection (replace)
pm.select(selCoords, replace=True)
# Reduce that selection by deselecting previous shell
pm.select(selShell, deselect=True)
selCoords = pm.ls(selection=True, flatten=True)
# Recalculate number of UVs left
uvRemain = len(selCoords)
# Add shell to list
listFinal.append(selShell)
pm.select(clear=True)
# Close progress window
pm.progressWindow(endProgress=True)
# Return shell list
return listFinal
I know what is taking so long: selections. I’ve been told by more experienced programmers that the select-command is slow, and that it’s always better to work on the raw data instead of working with selections and reading data on the fly.
But I know of no other way for collecting UV shells than this. There’s probably some super-speedy Maya API way of getting all the UV shells but C++ isn’t in my skills-toolbox
Any advice?