Exporters and engines aside, let’s assume that I manually want to modify the UV set order (indices) in Maya by simply cloning and copying UV sets.
A simple task I thought, but for some reason this code doesn’t work even though the print statements claims it does:
import pymel.core as pm
import copy
sortedList = []
sortedListOrg = []
# Get selection...
selObj = pm.ls(selection=True)[0].getShape()
# ...and query UV set names and indices
uvIndices = pm.polyUVSet(selObj, query=True, allUVSetsIndices=True)
uvNames = pm.polyUVSet(selObj, query=True, allUVSets=True)
uvSetDict = dict(zip(uvNames, uvIndices)) # Create keypairs
sortedList = sorted(uvSetDict, key=uvSetDict.get) # Sorted list
sortedListOrg = copy.copy(sortedList) # Copy
# Flip order in sortedList
sortedList.reverse()
count = 0
while count < len(uvSetDict):
temp = sortedListOrg[count]
pm.polyUVSet(
copy=True,
newUVSet=temp+"_t",
uvSet=temp,
)
sortedList.append(temp+"_t")
count += 1
print("Created copy of %s called %s")%(temp, temp+"_t")
# Copy sets and place them in the correct order
count = 0
dictSize = len(uvSetDict)
while count < dictSize:
# Copy
copyIndex = count + dictSize
pm.polyUVSet(
copy=True,
newUVSet=sortedListOrg[count],
uvSet=sortedList[copyIndex],
)
print("Copied %s to %s")%(sortedList[copyIndex], sortedList[count])
count += 1
Create a cube, clone the UV set. Name the sets A and B (optional ofc).
Move the coords in one of the sets so you can tell the difference between A and B.
Run the code.
Notice that the clone of A isn’t copied into B (and the clone of B isn’t copied into A).
Additionally, there is no construction history suggesting that the copy even took place!!
Why doesn’t this work?