Tuesday, 10 September 2019

Convert MEL to Python

Still converting MEL to python the oldschool way by deleting semi-colon here, adding a bracket there?

Pffffttt just use this!



import pymel.tools.mel2py as mel2py

print mel2py.mel2pyStr("""spaceLocator -p 0 0 0;""")


Output:


spaceLocator(p=(0, 0, 0))



Remember to add a cmds. to the start, because for some reason it doesn't add it on for you!

Now you can just replace 'spaceLocator -p 0 0 0;'  with any other MEL code that the script editor may spit out whilst you're Maya'ing and BAM insta-python!

Sure, it doesn't work for all cases but for other cases where you just want to copy & paste a handy addAttr line and can't be bothered to google it, it can come in handy and help speed things along.

2 comments:

  1. import pymel.core as pm
    shrinkWrapNode = pm.deformer('pSphere1', type='shrinkWrap')[0]
    pm.PyNode('pTorus1').worldMesh[0] >> shrinkWrapNode.targetGeom
    shrinkWrapNode.closestIfNoIntersection.set(True)

    ReplyDelete
  2. Delete -r R_B_controlArm_transform_grp_parentConstraint1 ;
    Delete -r L_B_controlArm_transform_grp_parentConstraint1 ;

    ReplyDelete