Home Technical Talk

passing python variables to a mel function via maya.mel.eval()

passerby
polycounter lvl 12
Offline / Send Message
passerby polycounter lvl 12
just wondering if any of the more technical maya users, know if there is a way to pass on a variable from your python script to a function your accessing through the maya.mel.eval() method.

haveing a problem with the "attributExists" mel function not being available in python, so im trying to get it doing something like.
import maya.cmds as cmds
import maya.mel as mel
mel.eval('attributeExists, "Tag", item' )

i just dont got anyway to get the needed information into the mel $item variable from the one that exists in my python script.

Replies

  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    an NVM i figured out i have to treat everything after mel.eval(
    as 1 big string, not like arguments so all i had to do was drop in a ' before the item variable and add the variable to the string.
    import maya.cmds as cmds
    import maya.mel as mel
    
    mel.eval('attributeExists "Tag"' + item):
    

    thanks anyways just me having a slow day and the syntax for running mel commands from python is pretty bad.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Yeah i dont really enjoy mel eval. Just code up the stuff in python. You a) build a library of handy mel stuff you can import and b) do more python :D
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    Yeah i dont really enjoy mel eval. Just code up the stuff in python. You a) build a library of handy mel stuff you can import and b) do more python :D

    ya i looked up the mel code for that function, and will write myself a py version tomorrow morning when i get back to this.

    im actully haveing a similar problem again, with FBXExport, there seems to be no python way expect mel.eval to get to it, and it's is supplied by a mll modual not a mel file so i cant just re-write it.

    was thinking
    mel.eval( 'FBXLoadPresetFile -f' + presetpath )
    

    would get me what i want but that doesn't work, only way i got it to work was just writing out my path, instead of using my variable that is set via my scripts UI.

    aside from the mel.eval stuff im really loving python for maya scripts over mel, though. A lot cleaner code and very easy language to learn.
Sign In or Register to comment.