def mel2pyStr(text):
    """
    Convert a mel command to pymel command and print the result
    @param text: The mel command
    """
    if not text.endswith(";"):
        pyLog.warning('Please end the mel code with ";"')
    else:
        import pymel.tools.mel2py as py2mel
        print py2mel.mel2pyStr(text, pymelNamespace="pm")
Exemple #2
0
def mel2pyStr(text, namespace):
    """
    Convert a mel command to pymel command and print the result
    @param text: The mel command
    @param namespace: The module name
    """
    if not text.endswith(";"):
        logger.warning('Please end the mel code with ";"')
    else:
        import pymel.tools.mel2py as py2mel
        print py2mel.mel2pyStr(text, pymelNamespace=namespace)
Exemple #3
0
def mel2pyStr(text, namespace):
    """
    Convert a mel command to pymel command and print the result
    @param text: The mel command
    @param namespace: The module name
    """
    if not text.endswith(";"):
        logger.warning('Please end the mel code with ";"')
    else:
        import pymel.tools.mel2py as py2mel
        print py2mel.mel2pyStr(text, pymelNamespace=namespace)
def em2pConvMel2Py():
    u'''translate MEL to Python'''
    melCmd = pm.scrollField('em2pTextEditMEL', q=1, tx=1)

    pyCmd = mel2py.mel2pyStr(melCmd, pymelNamespace='pm')
    pyFixed = pyCmd.replace("pymel.all", "pymel.core")
    pm.scrollField('em2pTextEditPy', e=1, tx=pyFixed)
Exemple #5
0
    def assertMelAndPyStringsEqual(self, melString, verbose=False):
        if verbose:
            print("Original mel string:")
            print(melString)

        #melCmd = '$tempStringVar = %s; print $tempStringVar; $tempStringVar = $tempStringVar;' % melString
        melCmd = '$tempStringVar = %s;' % melString
        if verbose:
            print("Mel assignment command:")
            print(melCmd)
        strFromMMEval = maya.mel.eval(melCmd)

        if verbose:
            print("Decoded through maya.mel:")
            print(strFromMMEval)

        pyCmd = mel2pyStr(melCmd)
        if verbose:
            print("Python assignment command:")
            print(pyCmd)
        exec_globals = {}
        exec(pyCmd, exec_globals)
        strFromPy2Mel = exec_globals['tempStringVar']

        if verbose:
            print("Decoded through py2mel:")
            print(strFromPy2Mel)

        self.assertEqual(strFromMMEval, strFromPy2Mel)
Exemple #6
0
def mel2pyDialog():
    """ this convert mel to python file.
   
    how to use:
    from rigWorkshop.ws_user.jun.utils import pyMel
    #mel to pymel convertor.
    pyMel.mel2pyDialog()
    """

    result = pm.promptDialog(title='mel2py convertor',
                             message='Enter Name:',
                             button=['OK', 'Cancel'],
                             defaultButton='OK',
                             cancelButton='Cancel',
                             dismissString='Cancel')

    if result == 'OK':
        text = pm.promptDialog(query=True, text=True)

        # Get the PyMel equivalent
        pmAnswer = mel2py.mel2pyStr(text, pymelNamespace='pm')

        # Get rid of the old way
        pmCode = pmAnswer.replace("pymel.all", "pymel.core")
        print(pmCode)
Exemple #7
0
 def assertMelAndPyStringsEqual(self, melString, verbose=False):
     if verbose:
         print "Original mel string:"
         print melString
         
     #melCmd = '$tempStringVar = %s; print $tempStringVar; $tempStringVar = $tempStringVar;' % melString
     melCmd = '$tempStringVar = %s;' % melString
     strFromMMEval = maya.mel.eval(melCmd)
 
     if verbose:
         print "Decoded through maya.mel:"
         print strFromMMEval
         
     exec mel2pyStr(melCmd)
     strFromPy2Mel = tempStringVar
     
     if verbose:
         print "Decoded through py2mel:"
         print strFromPy2Mel
     
     self.assertEqual(strFromMMEval, strFromPy2Mel)
Exemple #8
0
    def assertMelAndPyStringsEqual(self, melString, verbose=False):
        if verbose:
            print "Original mel string:"
            print melString

        #melCmd = '$tempStringVar = %s; print $tempStringVar; $tempStringVar = $tempStringVar;' % melString
        melCmd = '$tempStringVar = %s;' % melString
        strFromMMEval = maya.mel.eval(melCmd)

        if verbose:
            print "Decoded through maya.mel:"
            print strFromMMEval

        exec mel2pyStr(melCmd)
        strFromPy2Mel = tempStringVar

        if verbose:
            print "Decoded through py2mel:"
            print strFromPy2Mel

        self.assertEqual(strFromMMEval, strFromPy2Mel)
Exemple #9
0
def parse_mel_cmd(melStr):
    """Return the command, args and kwargs for a MEL command string"""

    # Get python variant and split of pymel import line
    import pymel.tools.mel2py as mel2py
    pyCmd = mel2py.mel2pyStr(melStr)
    pyCmd = pyCmd.splitlines()[1]
    print pyCmd

    cmd, arguments = pyCmd.split("(", 1)
    args, kwargs = eval("dummy" + "".join(pyCmd.partition("(")[1:]), {},
                        dict(dummy=lambda *x, **y: (x, y)))
Exemple #10
0
 def convert(meltext):
     try:
         pmAnswer = mel2py.mel2pyStr(meltext, pymelNamespace='pm')
         # get rid of old all
         pmCode = pmAnswer.replace("pymel.all", "pymel.core")
         pmCode = pmCode.replace("pm.pm.cmds.", "pm.")
         print(pmCode)
         global textbox_out
         textbox_out.setPlainText(pmCode)
     except:
         pmCode = '## Error converting ##\n## Check Script Editor for details ##'
         textbox_out.setPlainText(pmCode)
         raise
     return pmCode
Exemple #11
0
import pymel.core as pymel
import pymel.tools.mel2py as mel2py
result = pymel.promptDialog(title='Convert Mel to Python',
                            message='Enter Mel string: ',
                            button=['OK', 'Cancel'],
                            defaultButton='OK',
                            cancelButton='Cancel',
                            dismissText='Cancel')

if result == 'OK':
    text = pymel.promptDialog(query=True, text=True)

    #get the pymel equivalent
    pymelAnswer = mel2py.mel2pyStr(text, pymelNamespace='mc')

    #get rid of the old way
    pymelCode = pymelAnswer.replace('pymel.all', 'maya.cmds')
    print(pymelCode)
Exemple #12
0
"""
Turn mel to PyMel
"""
__author__ = 'pcuser'


import pymel.core as pm
import pymel.tools.mel2py as mel2py

result = pm.promptDialog(
                title='MEL to PyMEL',
                message='Enter MEL code:',
                button=['OK', 'Cancel'],
                defaultButton='OK',
                cancelButton='Cancel',
                dismissString='Cancel')

if result == 'OK':
        text = pm.promptDialog(query=True, text=True)
        pmCode = mel2py.mel2pyStr(text, pymelNamespace='pm')

        print pmCode.replace("pymel.all", "pymel.core")

Exemple #13
0
                else:
                    pm.parent( obj, gpar )  

    @staticmethod
Exemple #14
0
def processSyntax(*args):
    melString = melText.getText()
    convertedString = mel2py.mel2pyStr(melString)
    pythonCollected.setText(convertedString)