Removing unknown nodes from your scene

I’ve recently found myself working in files with which
a co-worker has used a plugin which I don’t have.
Said plugin has created nodes which my version of Maya
does not recognize, so on load I get the classic error raised :

errors

Through dealing with this I’ve developed a solution:
Find and delete said nodes!….. Brutal.

Now we can find these nodes using

import maya.cmds as cmds
unknownNodes = cmds.ls(type = 'unknown')
print unknownNodes 

But if we try to delete them we get an error “#Error: Node is locked and cannot be deleted.”

so we need to unlock them with:

for node in unknownNodes:
    cmds.lockNode(node, lock = False)

then we can delete them with:

for node in unknownNodes:
    cmds.delete(node)

No bringing it all together in one script:

import maya.cmds as cmds
unknownNodes = cmds.ls(type = 'unknown')
for node in unknownNodes:
    print 'deleting: ' + node
    cmds.lockNode(node, lock = False)
    cmds.delete(node)

And there you have it! No longer shall you be plagued by errors on boot up :)