Monday, February 3, 2014

find all instanced nodes in your Maya scene and make them unique

I ran across another great little uninstancer script, this one for uninstancing transforms and shapes, not the actual instancer node.  It uses the isInstanced API call and creates unique transform and shapes for all instanced nodes (again, nothing to do with the instancer node).
This comes from www.akeric.com/blog/?p=1087 if you want a more thorough explanation (edit, the script originates from the great mayamel.tiddlyspot.com.)


Here's the code.  Run uninstance() after sourcing these two functions:

import maya.cmds as mc
import maya.OpenMaya as om

def getInstances():
    instances = []
    iterDag = om.MItDag(om.MItDag.kBreadthFirst)
    while not iterDag.isDone():
        instanced = om.MItDag.isInstanced(iterDag)
        if instanced:
            instances.append(iterDag.fullPathName())
            print iterDag.fullPathName()
        iterDag.next()
    return instances
    
    
def uninstance():
    instances = getInstances()
    while len(instances):
        parent = mc.listRelatives(instances[0], parent=True, fullPath=True)[0]
        mc.duplicate(parent, renameChildren=True)
        mc.delete(parent)
        instances = getInstances()



No comments:

Post a Comment