• Helping you upgrade your CG career

    How to run mel commands inside a python script

    I use melscript, but am new to python in Maya. In a python script that I am writing, I have to run mel command, because the melscript documentation says that this command is not available in python ( the command that I want to run is getenv ). So how can I run the command getenv in a python script? thanks
    asked 2 Years ago by
    Avatar image of CG Helpline user ludwig.grahn

    CGH Score : 7
    Add a Comment for this question
    Please Login or Register to add comment
    1 Answers :

    You can do this in 2 ways depending on whether you are using pymel or not. You can get access to getenv in Pymel, with the mel module. Without PyMel, you can use the mel.eval function, which accepts a string of MEL command.

    Without PyMel :

    import maya.mel as mel
    myEnv = mel.eval("getenv PYTHONPATH")
    print myEnv

    With PyMel :

    import pymel.core as pm
    myEnv = pm.mel.getenv("PYTHONPATH")
    myEnv = pm.mel.getenv("MAYA_SCRIPT_PATH")

    In both cases, the return value will be a string, where the paths will be separated by semi-colon ; So you will have to split the string to get individual paths.

    answered 2 Years ago by
    Avatar image of CG Helpline user aaachooo

    Cambridge, United Kingdom
    CGH Score : 142
    Expertise : Maya; Python; Maxscript;
    Thanks for the quick reply ! I have posted another question, could you help please
    Add a Comment for this answer
    Please Login or Register to add comment

    Submit your Answer :


    Page rendered in 0.1485 seconds. Memory usage : 3.97MB.