How to verify if an node exist in the scene?


#1

Hey guys!
i am new for python, i am sorry for the begginner doubt…

how can i verify if an node exist in the scene?

in maxscript i usually do this:
if someting == undefined do print “do not exist”

how can i make it in python?

i would like to get someting like this:

if transformNode exists:
cmds.delete(transformNode)

thank you everyone!


#2
import maya.cmds as cmds
if cmds.objExists(node_name):
    cmds.delete(node_name)

#3

woww man! thank you so much!!!


#4

You can also, via pymel, do something like this:


import pymel.core as pm
try:
    node = pm.PyNode("node_name")
    pm.delete(node)
except pm.MayaNodeError: 
    pass

The above is a bit more pythonic. Rather than checking for existence, assume it’s there and if not, handle the issue.


#5

thanks a lot, sorry for delay the replying!