Advertisement
Guest User

Untitled

a guest
Sep 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import os.path
  2. import maya.cmds as mc
  3.  
  4. '''
  5.  
  6. you can call script from this command at the end of the code
  7. fastTextureReplacePath()
  8.  
  9. it will search based on the path of your scene, i.e., it will seek inside subfolders in the folder where your scene is
  10.  
  11. but if you run the script such this
  12. fastTextureReplacePath( 'C:/Project1/Character1/textures/' )
  13. it will start to seek the textures from this specified folder as a root, i.e. it will seek for your textures inside of subfolders of this root folder
  14.  
  15. '''
  16.  
  17. def fastTextureReplacePath( pathToSearch=None):
  18. files = mc.ls( typ='file' )
  19. for f in files:
  20. texturePath = mc.getAttr( f + '.fileTextureName' )
  21. if texturePath:
  22. if not os.path.isfile(texturePath):
  23. dir = mc.file( q=1, exn=1 ).rsplit( '/', 1 )[0]
  24. if pathToSearch:
  25. dir = pathToSearch
  26. fileName = texturePath.rsplit( '/', 1 )[-1]
  27. allPaths = [ x[0].replace('\\', '/') + '/' + fileName for x in os.walk(dir) if fileName in x[-1] ]
  28. if allPaths:
  29. finalPath = allPaths[0]
  30. if len(allPaths)>1:
  31. matchedPaths = [ len( set( k.split('/') ) & set( texturePath.split('/') ) ) for k in allPaths ]
  32. finalPath = allPaths[ matchedPaths.index( max( matchedPaths ) ) ]
  33. mc.setAttr( f + '.fileTextureName', finalPath, type='string' )
  34.  
  35. fastTextureReplacePath()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement