Advertisement
Flynny85

UVShrink

Oct 4th, 2016
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. ## how to use:
  2. ## select a poly face of each UV shell island you would like to scale and hit apply.
  3. ## command to run from Maya python window/shelf (copy + paste exactly the following inside the """ box while changing the path):
  4. """
  5.  
  6. filepath = "C:\Users\UserName\Documents\maya\scripts\MayaPythonTools"       ## << change this path to your folder.
  7. paths = sys.path ; sys.path.append(filepath) ; exec 'import ' + 'UVShrink' in globals(); exec( 'reload( ' + 'UVShrink' + ' )' ) in globals();
  8.  
  9.  
  10. """
  11.  
  12. import maya.cmds as cmds
  13. import maya.mel as mel
  14.  
  15. def variables(varType):
  16.     toolID = 'UVShrink'
  17.     returnData = eval(varType)
  18.     return returnData
  19.  
  20. def ShrinkUV():
  21.     _selected_Meshs = cmds.ls( selection = True , flatten = True )
  22.     cmds.select(clear = True)
  23.     for _item in _selected_Meshs:
  24.         cmds.select(_item)
  25.         mel.eval('polySelectBorderShell 0;')
  26.         _tempBoundingBox = cmds.polyEvaluate( bc2 = True , ae = True)
  27.         _tempPivot = [ 0,0]
  28.         _tempPivot[0] = ((_tempBoundingBox[0][0] + _tempBoundingBox[0][1]) /2 )
  29.         _tempPivot[1] = ((_tempBoundingBox[1][0] + _tempBoundingBox[1][1]) /2 )
  30.         _scale = cmds.floatSlider( 'UVShrink_Float_UI' , query = True , value = True )
  31.         cmds.polyEditUV( pu = _tempPivot[0] , pv = _tempPivot[1] , su = _scale, sv = _scale )
  32.         cmds.select(clear = True)
  33.     cmds.select(_selected_Meshs)   
  34.  
  35. def UpdateWindowValue():
  36.     fullLabel = str(cmds.floatSlider( 'UVShrink_Float_UI' , query = True , value = True ))
  37.     cmds.text( 'UVShrink_Float_UI_Text' , edit = True , label = str(fullLabel[0:4])   )
  38.  
  39. def UVShrink_Window():
  40.     UVShrink_Window = "UVShrink_Window"
  41.     if cmds.window(UVShrink_Window, exists = True):
  42.         cmds.deleteUI(UVShrink_Window, window = True)
  43.     if cmds.windowPref(UVShrink_Window, exists = True):
  44.         cmds.windowPref(UVShrink_Window, remove = True )
  45.     cmds.window(UVShrink_Window ,  rtf = True , toolbox = True , wh = (200, 55) )
  46.     cmds.columnLayout( adjustableColumn=True )
  47.     cmds.floatSlider( 'UVShrink_Float_UI' , min= .01, max=2.0, value=.2, step=1 , cc = ( variables('toolID') + '.UpdateWindowValue()') )
  48.     cmds.text( 'UVShrink_Float_UI_Text' ,label='0.2' )
  49.     cmds.button( label='Apply', command= ( variables('toolID') + '.ShrinkUV()') )
  50.     cmds.setParent( '..' )
  51.     cmds.showWindow( UVShrink_Window )
  52.  
  53. def init():
  54.     UVShrink_Window() ## run self
  55.  
  56. UVShrink_Window()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement