I believe Justin hit the most important point regarding exec() in MEL versus exec() in Python versus execfile() in python. These commands are all quite different.
However, there are some major caveats to execfile(). Using it will mix your namespace with the currently running script. Perhaps this is the feature that you are relying on. Are you collecting the value of Returned after executing your script? If so, this sort of back-handed variable can lead to very confusing code and make it hard to debug in the future. As an alternative, this is how I would design your code: 1. Skip the userSetup.mel file and instead use userSetup.py. Maya will execute every userSetup.py in the PYTHONPATH. You can still have your current userSetup.mel. Both will run. 2. You should then make sure your script, SaveLPLFile.py, is in the python path. This can be done through PYTHONPATH or a sys.path.append in the userSetup.py. 3. Restructure your script to be used a module. It's common to wrap all the bare code in a function named main(). 4. Call your new module from userSetup.py import SaveLPLFile SaveLPLFile.main() I'd be happy to further discuss the program design if that's interesting to you. Cheers, Jesse On Thu, Dec 12, 2013 at 11:56 AM, Justin Israel <[email protected]>wrote: > exec (MEL) > "The string argument is a command which gets executed as a background > process from the shell" > > That would be launching your python script in its own process, outside of > Maya, and most likely failing but you aren't checking the return code to > know. > > I think what you really want is the python "execfile" > "Read and execute a Python script from a file. > The globals and locals are dictionaries, defaulting to the current > globals and locals. If only globals is given, locals defaults to it." > > Also, just use forward slashes all the time, even on Windows > > Does this work the way you expect? > > python("execfile('/Server/MyFolder/Save/LPLFile.py')") > > > > > On Fri, Dec 13, 2013 at 8:10 AM, <[email protected]> wrote: > >> I'd like to run a Maya Python Script (NOT a single Python command) from >> within my userSetup.mel script. The Python script is simple but does use >> some Maya-specific commands. The Pythong script for testing is: >> >> #Python script: >> import maya.cmds as cmds >> Returned=cmds.fileDialog(mode=1, title="Save Layer/Pass list for >> Miranda:") >> >> >> >> The closest I've gotten to running it from MEL is something like: >> >> //Within the MEL Script: >> python (exec("\\Server\MyFolder\SaveLPLFile.py")); >> >> >> I've tried various cnfigurations of \\, \\\\, //, etc to accomodate the >> potential errors of escape characters but nothing seems to have any effect. >> The python/exec command appears to run without error (to the Maya console) >> but the actual script is not running because a cmds.fileDialog() never >> appears. Even when there is a typo in the filename the command appears to >> run.....apparently there is some long-standing bug in python that doesn't >> return an error message properly under some instances. >> >> Any alternatives that might be a better method of running a Python script >> from within MEL? >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/231755dc-700c-4961-bc54-1a214ac0fc75%40googlegroups.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0SrN0GktQO_RhaqtmopaYa%2BmZRfGUS3N_Y6_nc5BckCQ%40mail.gmail.com > . > > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CANESWi1%3DzLcAW9KcY72_PH210aPWixVbq%2Bvuc%2Bgy4X0HnZVbvw%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
