PDA

View Full Version : Error Raise in PyMel


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

pm.listRelatives(pm.listRelatives('prevObj_Root|*',ad=True,type='nurbsCurve'),p=True)

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\pmcmds.py line 104: #

So i was follow this and add a few extra

try:
......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

NaughtyNathan
07-22-2012, 11: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!'
else:
curves = pm.listRelatives(curveShapes, p=True)
alternatively, if not curveShapes simply return or raise an error or whatever.

noobmode
07-22-2012, 11: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-22-2012, 11: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.