View Full Version : Error Raise in PyMel

07 July 2012, 05:15 AM
I have some folder name prevObj_Root which store nurbsCurve inside.So i use this command to select all of them


It's ok as long as there're nurbsCurve inside it, or else it will raise an error

# Error: MayaNodeError: file C:\Program Files\Autodesk\Maya2011\Python\lib\site-packages\pymel\internal\ line 104: #

So i was follow this and add a few extra

......a = pm.listRelatives(pm.listRelatives('prevObj_Root|*',ad=True,type='nurbsCurve'),p=True)
except MayaNodeErrror:
......a = []

And now Maya raise an NameError that MayaNodeError is not assign or defined.
Anything would help, thanks

07 July 2012, 10:36 AM
I don't know how to solve your specific error and make work what you want to work, but I will say, don't do it like that, you're doing it "wrong".

Don't try to cram several steps into a single line of code as it makes it harder to read, understand and consequently debug, and it doesn't make your code look any cleverer or run faster or more efficiently (in real terms)

list the curves under your group into a variable and then simply check if there are any before continuing. something like:

curves = [] # start with an empty list of curves
curveShapes = pm.listRelatives('prevObj_Root|*', ad=True, type='nurbsCurve')
if not curveShapes:
print 'no curves found under group!'
curves = pm.listRelatives(curveShapes, p=True)
alternatively, if not curveShapes simply return or raise an error or whatever.

07 July 2012, 10:41 AM
Thank Nathan
Because the first listRelatives command return a [], so the next command raise an error. I know if separate the command like that, it will easy to read, for me and other people too. However i use that a lot so i would want to shorten it a little.

But i wonder why the try, except not work, i did write correct the error's name, right?

CGTalk Moderation
07 July 2012, 10:41 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.