Search code examples
python-3.xmayapymel

Maya 2023 pymel I can't access mel2py with python3


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 )

Solution

  • 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)