simple tricky procedure: running python file from a mel file

simple tricky procedure: running python file from a mel file

jay.natrajan
Community Visitor Community Visitor
1,210 Views
1 Reply
Message 1 of 2

simple tricky procedure: running python file from a mel file

jay.natrajan
Community Visitor
Community Visitor

Hello Folks,

 

this is a simple basic question, 

from a mel script how does one run a python file which includes maya python as well,

 

i did try various methods including running calling this command,

python (exec ("pathtoFile/ SaveLPLFile.py")); from mel does not work

 

and other methods that i had come across as well but nothing seem to work,

would be great to get a way which works with running python and maya python from mel file

 

ex:

mel script 

AddLongAttribute( "JobPriority" );

if( GetCurrentRenderer() == "mentalRay" )
        setAttr defaultRenderGlobals.deadlineJobPriority 60;

runThis.py

 

python script runThis.py

 

import maya.cmds
import os,sys

filepath = "/mnt/filePath/Maya/Check.txt"

 

def readFromFile()
       fileOpenIn = open(os.path.join(filepath,'r'))
       do something
       fileOpenIn.close()

 

def setRenderer()
       setRenderer = "renderman"
       cmds.optionVar(sv=('preferredRenderer',setRenderer))
       readFromFile()

 

if __name__ == __main__:
       setRenderer()

 

Thanks,

Jay

 

 

0 Likes
1,211 Views
1 Reply
Reply (1)
Message 2 of 2

dankeating3d
Explorer
Explorer

 

you should be able to use the python command

 

https://download.autodesk.com/us/maya/2011help/Commands/python.html

 

something like :

python("import runThis")

 

NOTE - the python command takes a string as an input. So you needs quotes inside the brackets. Your example does not have quotes. 

0 Likes