Wednesday 1 March 2017

fix texture paths maya

https://mayapy.wordpress.com/2012/04/23/fix-texture-paths-in-maya-python-script/


import maya.cmds as cmds
import os

def renameTex(newName):
        tex=cmds.ls(sl=True,type="file")
for item in tex:
fullpath = cmds.getAttr("%s.fileTextureName" %item)
fileName= fullpath.split("/")[-1]
newPath= os.path.join(newName,fileName)
cmds.setAttr("%s.fileTextureName" %item, newPath,type="string")

def selectDir():
 folder=cmds.fileDialog2(cap="locate folder",fm=3)
 uniToStr=str(folder)

 filePath=uniToStr.split("'")[1]
 cmds.textField(pathText, edit=True,text=filePath)
 global newName
 newName=filePath

win=cmds.window(title="RV TEXTURE PATH FIX",w=350,h=150)
cmds.columnLayout(adjustableColumn=True )
cmds.text("FIRSTlect your file nodes in Hypershade!!",bgc=(1,0,0))
cmds.frameLayout(l="browse folder for textures")
cmds.flowLayout()
cmds.text("file",h=25)
pathText=cmds.textField(w=250,h=25)
loadBtn=cmds.button(w=50,h=25,label="get",c="selectDir()")

cmds.setParent( '..' )
fixit=cmds.button(l="Fix textures", c="renameTex(newName)")
cmds.setParent( '..' )

cmds.showWindow(win)