Delete unknown nodes in Maya

Dec 30 2008


Sometimes you need to delete unknown nodes in a Maya scene. You can do it in the following python snippet.

from pymel import *
def deleteUnknownNodes():
    # 2 things to take care of:
    #   1) you can't delete nodes from references.
    #   2) "delete" will delete all children nodes (hierarchy) in default.
    unknown = ls(type="unknown")
    unknown = filter(lambda node: not node.isReferenced(), unknown)
    for node in unknown:
        if not objExists(node):

Compare it to the MEL way:

proc dgSaveDeleteUnknown()
    string $unknown[] = `ls -type "unknown"`;
    if( size($unknown) ) { 
        int $i; 
        for($i=0; $i<size($unknown); $i++) {
            if(!`objExists $unknown[$i]`)
            if(!`referenceQuery -inr $unknown[$i]`)
                delete $unknown[$i];

But why do we need to do that? I mean, why do we need to delete unknown nodes and where do those nodes come from? In theory, there should be no unknown nodes in a Maya scene file!

The answer is: Yes, you are right but if you are in an animation studio with complicated animation pipeline because animation is a vivid industry, it would happen to you!

Almost all unknown nodes come from 3rd-party Maya plugins. Let’s say, your colleagues used a magical Maya plugin (ex, Realflow) such that there are some RealFlowParticlerGetMaxRange, RealflowEmitter or RealflowMesh nodes in the Maya scene. You were the downstream of this Maya scene and unfortunately, your Maya didn’t know how to negotiate with those nodes (ex, you didn’t have the Realflow plugin or you forgot to load it), those nodes became unknown to Maya. You could delete those nodes if they were not contributing anything to your workflow. (Ex, you are in lighting department and the rendering of fluid simulation is not your business.)

comments powered by Disqus