A little python: transferFiles.py

There are times in both my freelance and studio work that I’ve come across the problem of working locally on a workstation, trying to port the project to a server then finding that the texture files have become absolute to the local workstation directories. In most projects I have a whole lot of files to convert to the project’s relative path, and so I have a little piece of MEL on hand for just the occasion.

During a recent work project 819 texture files were mapped to the artists c: drive. My MEL code worked but I was starting to see this issue creep into the studio workflow, so in an attempt to simplify this process for my colleagues I created a python script with a GUI so that others could utilize the script themselves if the issue arose.

There are two main functions to the script. The first allows the user to copy from the source directory to the destination directory (at the moment it has only been tested copying files from two different windows directories, I’ll have to dig deeper into the OS module to set it up for mac and linux later on). The copying will only allow the user to copy image files, and they are hard coded in for now. I’ve picked tif, png, tga, jpg, and hdr, as those are the most common in my studio. Trying to copy all of the files in a directory will often cause sporadic errors when copying a .mayaSwatches folder or other hidden windows file.

Once you have the destination directory set you can use the Run Conversion Now button to convert the old texture paths to the new destination folder chosen. The user can also put the copied files into any folder within the ‘sourceimages’ folder and it will still link them up.

Many thanks to my friend Lernie for his help, there were a few times my brain almost exploded in frustration. The video is just a small demonstration of how the script works. The script is available below – I’m still extremely new to python and learning it in my down time so this might not be the cleanest code but hey! it works.


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Powered by WordPress.com.

Up ↑

%d bloggers like this: