Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os.path
- import maya.cmds as mc
- '''
- you can call script from this command at the end of the code
- fastTextureReplacePath()
- it will search based on the path of your scene, i.e., it will seek inside subfolders in the folder where your scene is
- but if you run the script such this
- fastTextureReplacePath( 'C:/Project1/Character1/textures/' )
- 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
- '''
- def fastTextureReplacePath( pathToSearch=None):
- files = mc.ls( typ='file' )
- for f in files:
- texturePath = mc.getAttr( f + '.fileTextureName' )
- if texturePath:
- if not os.path.isfile(texturePath):
- dir = mc.file( q=1, exn=1 ).rsplit( '/', 1 )[0]
- if pathToSearch:
- dir = pathToSearch
- fileName = texturePath.rsplit( '/', 1 )[-1]
- allPaths = [ x[0].replace('\\', '/') + '/' + fileName for x in os.walk(dir) if fileName in x[-1] ]
- if allPaths:
- finalPath = allPaths[0]
- if len(allPaths)>1:
- matchedPaths = [ len( set( k.split('/') ) & set( texturePath.split('/') ) ) for k in allPaths ]
- finalPath = allPaths[ matchedPaths.index( max( matchedPaths ) ) ]
- mc.setAttr( f + '.fileTextureName', finalPath, type='string' )
- fastTextureReplacePath()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement