FIX Texture Paths in MAYA python script


Hi all.

Once in a while i get this headache of having to change texture paths by hand,

when a scene comes from another computer or colleague with diferent OS or

diferent texture paths.

So i’ve built this script to aid me. Hope it’s also usefull to you. cheers

import maya.cmds as cmds
import os

def renameTex(newName):,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)

	cmds.textField(pathText, edit=True,text=filePath)
	global newName

win=cmds.window(title="RV TEXTURE PATH FIX",w=350,h=150)
cmds.columnLayout(adjustableColumn=True )
cmds.text("FIRST > select your file nodes in Hypershade!!",bgc=(1,0,0))
cmds.frameLayout(l="browse folder for textures")
cmds.text("file Path",h=25)

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


28 thoughts on “FIX Texture Paths in MAYA python script

    • Hi Francois. please see if you copied and the pasted the code well. there might be some space in the beginning of the first line. As it says “Error: line 1”.

      • Actually is there an issue with this line ?,type=”fileor item in tex:
        because there is only one comma

  1. ———————– This is what you wrote,type=”fileor item in tex:

    ———————– This is the code,type=”file”)
    for item in tex:

    • Hey mayapy! Thank you for your code! They really saved my life. And do miss several code in your original code at the top. That’s where Francois pointed out 🙂

      Thank you for your work again! They really help me a lot!

      • actually…after my comments several mins ago published…the whole page got refreshed! And those code I mentioned are fixed!!! I don’t know what has happened but everything is actually good now. So weird..haha anyways! Sorry to bother you and thank you for your sharing!

      • It may be a display issue in the browser itself.
        but this is what it should look like:

        def renameTex(newName):,type=”file”)
        for item in tex:

  2. Thanks!!!! Had the same issue as Francois, it’s not displaying well here aswell, had to replace as suggested! Thanks a lot

  3. Hey thanks so much for this script! It is great!
    Want to point out that I think there may actually be a typo in the line you were referring to in the comments above.

    I got it to work the first time I had used a few months back. Since then something has changed… I had to go back to my old computer and re copy the old line…,type=”file”)
    for item in tex:
    Sorry not trying to be picky. It really is one of the easiest scripts I have found for relocating textures.

  4. The “bad” line of code cut and pasted by Francois is what is being displayed by my Chrome and Firefox browsers on Linux, even if the HTML source contains the “good” line of code.

  5. First, I am working in Maya 2017 and not much of a coder.

    The error:
    # Error: line 1: expected an indented block #

    I see the code has not been updated in the browser I am in now. It still has the

    def renameTex(newName):,type=”fileor item in tex:

    which is wrong as I can see in the comments.

    So I replaced it with

    def renameTex(newName):,type=”file”)
    for item in tex:

    Does it matter how the line is read above? My first 5 lines of code read:

    1:import maya.cmds as cmds
    2:import os
    4:def renameTex(newName):,type=”file”)for item in tex:

    Thanks in advance. I appreciate the code and your help.

  6. you are missing a tab.

    after the def line you should have indented text as bellow.
    def renameTex(newName):
    “one tab here”,type=”file”)
    “one tab here”for item in tex:
    “two tabs here”fullpath = cmds.getAttr(“%s.fileTextureName” %item)
    “two tabs here”fileName= fullpath.split(“/”)[-1]
    “two tabs here”newPath= os.path.join(newName,fileName)
    “two tabs here”cmds.setAttr(“%s.fileTextureName” %item, newPath,type=”string”)

  7. Thanks! This worked. Much appreciated. I wonder if this is a browser issue? It looked the same in Safari AND Chrome. Thanks again for your contribution!

  8. Hey, i’m not much of a coder, but I put the code in Maya 2017 and i fixed the code.

    I open Hypershade, select the texture, go to the new folder where the textures are, click fix textures but nothing happens…

    What’s going on?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s