Skip to content

Instantly share code, notes, and snippets.

@TSCG
Created August 6, 2019 04:02
Show Gist options
  • Save TSCG/a4059b3a224aff178b92f48373db4bb1 to your computer and use it in GitHub Desktop.
Save TSCG/a4059b3a224aff178b92f48373db4bb1 to your computer and use it in GitHub Desktop.
選択したUVシェル同士を中心値で入れ替え
import maya.cmds as cmds
import maya.mel as mel
def TsUvShellReplacement():
posList = []
list = cmds.ls(sl=True, fl=True)
#Get center position.
for i in list:
cmds.select( i, r=True )
mel.eval("polySelectBorderShell 0;")
shapeName = cmds.listRelatives(i.split(".")[0], shapes=True)[0]
pos = cmds.getAttr("{0}.uvPivot".format(shapeName))
posList.append( pos[0] )
#Calculate moving value.
moveVal = [[posList[0][0]*-1 + posList[1][0], posList[0][1]*-1 + posList[1][1]],
[posList[1][0]*-1 + posList[0][0], posList[1][1]*-1 + posList[0][1]]]
#Move uvshell.
for i in range(2):
cmds.select( list[i], r=True )
mel.eval("polySelectBorderShell 0;")
uValue = moveVal[i][0]
vValue = moveVal[i][1]
cmds.polyEditUV( relative=1, uValue=uValue, vValue=vValue )
#Restore selected state.
cmds.select( list, r=True )
#TsUvShellReplacement()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment