Maya Clean Paste (pasted__)

This is a short (8 lines) script to clean up Maya after you copy and paste between scene files (if you’re doing it in the same file you should probably duplicate it instead). It gets rid of the “pasted__” prefix on all objects and ungroups the objects if an extra group was added when pasting.

NOTE: This script requires PyMEL. To use this script, you should paste the following into the Python section of the Script Window, and then execute the code. Or you could drag the selected code in the Python tab to the Shelf to create a shelf item for it.

## This script requires pymel

## This script is a quick and simple way to clean up a scene after
## copy and pasting in Maya. It searches for objects with the name
## starting with pasted__, ungroups them if they came in a group,
## and renames them. Pymel automatically renames them uniquely if
## needed.

## Import pymel
from pymel.core import *

## Stores a list of all objects starting with pasted__
pastedObjects = ls('pasted__*')

## For each thing in the list, store it as object
for object in pastedObjects:
    ## Get a list of it's direct parent
    rel = listRelatives(object, p=True)
    ## If that parent starts with group
    if 'group*' in rel:
        ## It came in root level and is pasted in a group, so ungroup it
        rel[0].ungroup()
    ## The new name is the objects name without pasted__
    newName = object.replace('pasted__', '')
    ## Rename the object with the new name
    rename(object, newName)

Leave a Reply