Maya Python Scripts: Batch Rename and Manage Materials
18 Sep 26 (1mo ago)
Managing hundreds of materials in Autodesk Maya can be a tedious process if done manually. Whether you are cleaning up a scene, organizing assets, or prepping for a render pipeline, using Python scripts is the fastest way to organize your node names.
Here are three handy Python scripts for Maya to help you list, search, and batch rename materials in your scene.
1. List Nodes by Suffix
If you need to audit your scene and find all nodes that share a specific naming convention (for example, ending in _mat1), this simple script will list them cleanly in the Script Editor.
import maya.cmds as cmds
def list_mat1_nodes():
# Finds everything ending in "_mat1" regardless of type
nodes = cmds.ls("*_mat1")
if not nodes:
print("No nodes found ending in '_mat1'")
return
# Sorts the list alphabetically for easier reading
nodes.sort()
print(f"--- Found {len(nodes)} nodes ---")
for node in nodes:
print(node)
list_mat1_nodes()
2. Batch Rename a Specific Suffix
Once you have identified nodes with an incorrect suffix, you can automatically replace it. This script finds all nodes ending in _mat1 and cleanly renames them to end with _mat.
import maya.cmds as cmds
def rename_mat1_to_mat():
# Find all nodes ending in _mat1
nodes = cmds.ls("*_mat1")
if not nodes:
print("No nodes found ending in '_mat1'")
return
print(f"--- Renaming {len(nodes)} nodes ---")
for node in nodes:
# Construct the new name by replacing the suffix
new_name = node.replace("_mat1", "_mat")
# Rename the node
result = cmds.rename(node, new_name)
print(f"Renamed: {node} -> {result}")
rename_mat1_to_mat()
3. Append a Suffix to All Materials
Sometimes you need to mark all existing materials in a scene for a specific pipeline step, such as adding a _TEMP suffix. This script applies the suffix to every material while safely ignoring Maya's default shaders to prevent scene errors.
import maya.cmds as cmds
def append_temp_to_materials():
# Get all materials in the scene
materials = cmds.ls(materials=True)
# Define materials we should NEVER rename
defaults = ['lambert1', 'particleCloud1', 'standardSurface1']
print(f"--- Processing {len(materials)} materials ---")
for mat in materials:
# Skip default materials or ones that already have the suffix
if mat in defaults or mat.endswith("_TEMP"):
continue
# Rename the material
new_name = f"{mat}_TEMP"
cmds.rename(mat, new_name)
print(f"Renamed: {mat} -> {new_name}")
append_temp_to_materials()
How to use these scripts: Open the Script Editor in Maya, paste the code into a Python tab, and press Ctrl + Enter (or Command + Enter) to execute.