not sure how robust this is, but it seems to work:

import maya.cmds as cmds
import maya.mel as mel
def isValidMelCmd( cmdStr ):
     undoState = cmds.undoInfo(q=1, state=1)
     cmds.undoInfo(state=1)
     isValid = None
     try:
         mel.eval(cmdStr)
     except:
         isValid = False
     else:
         isValid = True
         cmds.undo()
     finally:
         cmds.undoInfo(state=undoState)
     return isValid

isValidMelCmd( "setAttr persp.tx 2" )
# Result: True #
isValidMelCmd( "3etAttr persp.tx 2" )
# Result: False #

if you wanted to make it work for python statements, it wouldn't be  
hard. just use eval instead of mel.eval

-chad




On Aug 27, 2009, at 10:13 PM, Taylor Carrasco wrote:

> Is there a way to validate a mel command is valid (not necessarily  
> that it will execute properly) before running it?
>
> Something like .....
> cmdValid("setAttr "PUP1:root_ctrl.extraRotY" 20;") returns true
> cmdValid("3etAttr "PUP1:root_ctrl.extraRotY" 20;") returns false
>
>
> >


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

Reply via email to