Skip to content

Instantly share code, notes, and snippets.

@patwooky
Last active January 24, 2017 04:13
Show Gist options
  • Save patwooky/c2c906564fe5ec3f34b40a1e0147868c to your computer and use it in GitHub Desktop.
Save patwooky/c2c906564fe5ec3f34b40a1e0147868c to your computer and use it in GitHub Desktop.
Deactivate and activate all file texture nodes in Maya
from pymel.core import *
import os
'''
Written by Patrick Woo
Sometimes when Maya has an active connection to the texture files, they become locked and
the user cannot save over the filenames to update their contents.
In such a case the user can only unlock the file when the Maya session closes. This is quite annoying and ineffcient.
This code has two parts that does the following:
- disables and file nodes and sets their filenames to empty strings, and disables the file nodes
- sets filenames back to point to their original filenames and paths, and enables the file nodes again
When file nodes are disabled, most of the time Maya will close and unlock the files.
Sometimes when filenames are set to '', Maya will also unlock those files.
This script does both because I am paranoid.
'''
ftuple=[(x, x.fileTextureName.get()) for x in ls(type='file')]
# turn off, and hopefully the system closes the texture files
# so user can delete, rename, update, etc.
[x[0].fileTextureName.set('') for x in ftuple] # sets texture file path to empty
[x[0].nodeState.set(1) for x in ftuple] # disables file node
# turn back on
[x[0].fileTextureName.set(x[1]) for x in ftuple] # set back the correct file names
[x[0].nodeState.set(0) for x in ftuple] # enables file node again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment