Set all image plane images to a new path in Maya (Python)

Example: You want to grade or resize image plane images and write them to a new location with Nuke. To set all the file paths on the scene to the new path run this script. The images need to be in an image sequence. Replace new_path variable string with the file path pointing to the first image of the new image sequence. Replace file_ext variable string with the file extension of the new image sequence.

Logic around the script:

  • Get a list of all the image plane shape nodes in the scene with ls command with flag type=“imagePlane”

  • for each node in the list

    • get image name attribute to a variable

    • substring out the frame

    • construct a new file path from the prefix, frame, and file_ext variables

    • set image plane image name attribute to the final_path

import maya.cmds as cmds new_path = r"new_file_path\test_imageplane_newpath.1001.jpg" file_ext = ".jpg" prefix = new_path[0:(-4-len(file_ext))] nodes = cmds.ls( type='imagePlane' ) for node in nodes: image_name = cmds.getAttr ( node + '.imageName' ) frame = image_name[(-4-len(file_ext)):(len(file_ext)*-1)] final_path = prefix + frame + file_ext cmds.setAttr( node + '.imageName', final_path, type='string')
Previous
Previous

Create animated camera from multiple cameras in Maya (Python)

Next
Next

Send Email with Houdini (Python)