Maya 2023 pymel I can't access mel2py with python3

628 views Asked by At

I get this error and I think it's because of python3 Error: AttributeError: file C:\Program Files\Autodesk\Maya2023\Python\lib\site-packages\pymel\tools\mel2py\melparse.py line 438: 'str' object has no attribute 'lineno'

import pymel.tools.mel2py as mel2py
pythonCode = mel2py.mel2pyStr( """
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateX;
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateY;
setDrivenKeyframe -currentDriver pCube1.translateY pCube2.translateZ;
""",pymelNamespace='pm')
print( pythonCode )
3

There are 3 answers

0
Greymanic On BEST ANSWER

I believe the issue is down to how you're formatting the mel command string. If you use the code below it should function:

import pymel.tools.mel2py as mel2py
mel_command = 'setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateX";setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateY";setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateZ";'
pythonCode = mel2py.mel2pyStr(mel_command, pymelNamespace='pm')
print(pythonCode)
0
furcraea.tokyo On

A simple solution is to launch a maya2019 or maya2018 version prior to maya2022 and use mel2py there.

0
Guy Micciche On

As a side note, the string can be multi-line, but you had to add in the parentheses in your mel code. The mel code has to be perfectly formatted and working I think, in order for this to work. So this original code you posted works, but I just modified the mel string:

import pymel.tools.mel2py as mel2py
pythonCode = mel2py.mel2pyStr('''
setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateX";
setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateY";
setDrivenKeyframe "-currentDriver pCube1.translateY pCube2.translateZ";
''',pymelNamespace='pm')
print( pythonCode )