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")
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)
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)
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)
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)
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)))
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
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)
""" 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")
else: pm.parent( obj, gpar ) @staticmethod
def processSyntax(*args): melString = melText.getText() convertedString = mel2py.mel2pyStr(melString) pythonCollected.setText(convertedString)