Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Delete unknown nodes in Python

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
13843 Views, 3 Replies

Delete unknown nodes in Python

Anonymous
Not applicable

Is there a way to delete unknown noeds from within Maya using Pyhton

 

#Something like...

for item in unknownNodes:
  if node.exists:
    delete node

print unknownNodes # []

0 Likes

Delete unknown nodes in Python

Is there a way to delete unknown noeds from within Maya using Pyhton

 

#Something like...

for item in unknownNodes:
  if node.exists:
    delete node

print unknownNodes # []

3 REPLIES 3
Message 2 of 4
haggi_master
in reply to: Anonymous

haggi_master
Advocate
Advocate
import maya.cmds as cmds
cmds.delete(cmds.ls(type="unknown"))

import maya.cmds as cmds
cmds.delete(cmds.ls(type="unknown"))
Message 3 of 4

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

import maya.cmds as cmds
unknownNodes=cmds.ls(type = "unknown")
for item in unknownNodes:
    if cmds.objExists(item):
        print item
        cmds.delete(item)

import maya.cmds as cmds
unknownNodes=cmds.ls(type = "unknown")
for item in unknownNodes:
    if cmds.objExists(item):
        print item
        cmds.delete(item)

Message 4 of 4

ijdallas
Explorer
Explorer

Thanks, rajasekaransurjen, your code handles ALMOST all the unknown nodes.

 

It looks like there's another type, "unknownDag" that Maya also uses (eg for Mental Ray nodes if the plugin isn't loaded). I updated your code to include that type, and to unlock nodes before deleting them since Maya will refuse to delete any locked nodes:

 

import maya.cmds as cmds
unknownNodes=cmds.ls(type = "unknown")
unknownNodes+=cmds.ls(type = "unknownDag")
for item in unknownNodes:
    if cmds.objExists(item):
        print item
        cmds.lockNode(item, lock=False)         cmds.delete(item)

 

A recent Autodesk post also discusses a few more ways to remove unknown nodes, for example by using the Optimize Scene Size command: https://knowledge.autodesk.com/support/maya/troubleshooting/caas/sfdcarticles/sfdcarticles/Unable-to...

Thanks, rajasekaransurjen, your code handles ALMOST all the unknown nodes.

 

It looks like there's another type, "unknownDag" that Maya also uses (eg for Mental Ray nodes if the plugin isn't loaded). I updated your code to include that type, and to unlock nodes before deleting them since Maya will refuse to delete any locked nodes:

 

import maya.cmds as cmds
unknownNodes=cmds.ls(type = "unknown")
unknownNodes+=cmds.ls(type = "unknownDag")
for item in unknownNodes:
    if cmds.objExists(item):
        print item
        cmds.lockNode(item, lock=False)         cmds.delete(item)

 

A recent Autodesk post also discusses a few more ways to remove unknown nodes, for example by using the Optimize Scene Size command: https://knowledge.autodesk.com/support/maya/troubleshooting/caas/sfdcarticles/sfdcarticles/Unable-to...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report