[Maya-Python] usage for "error" and "warning"?

1,061 views
Skip to first unread message

PixelMuncher

unread,
May 6, 2010, 6:32:11 PM5/6/10
to python_inside_maya
Hi All:

Maya throws an error when I try to use "error" and "warning" from
pymel in the root namespace:

warning ("A Warning")
# Error: NameError: file <maya console> line 1: name 'warning' is not
defined #
error ("This is an error")
# Error: NameError: file <maya console> line 1: name 'error' is not
defined #

When called from an external script the error message is:
NameError: global name 'warning' is not defined #

So I use a mel wrapper, which fixes "warning".
mel.warning ("A Warning")
# Warning: A Warning #

"mel.error" executes but also generates an runtime error:
mel.error ('This is an Error')
# Error: This is an Error #
# Error: RuntimeError: file C:\MiscApps\pymel\pymel\core\language.py
line 837: Error occurred during execution of MEL script #

Could someone tell me the correct usage for "error"?
Thanks.

--
http://groups.google.com/group/python_inside_maya

Paul Molodowitch

unread,
May 6, 2010, 8:58:55 PM5/6/10
to python_in...@googlegroups.com
Pymel doesn't provide an error or warning function because autodesk didn't provide a maya.cmds wrap for those.

If all you want to do is DISPLAY an error / warning (with the appropriate coloring) in the status window, you can use api.MGlobal.displayWarning / displayError (the name is from memory, might be slightly different).

If you want to raise an actual error, the standard python way to do that is with the raise statement, and an appropriate Exception class.

ie,

if argIsBad(arg):
    raise ValueError

It might make sense to include MGlobal.displayWarning / displayError in the pymel.core namespace, though, to make them more accessible... 

- Paul

--
http://groups.google.com/group/python_inside_maya

PixelMuncher

unread,
May 7, 2010, 1:04:19 PM5/7/10
to python_inside_maya
Thanks much Paul:
raise ValueError was what I was looking for.
displayWarning and displayError are available when I just use
from pymel.core import *
--
http://groups.google.com/group/python_inside_maya
Reply all
Reply to author
Forward
0 new messages