View Full Version : how to evaluate script every frame

01 January 2008, 10:24 AM
is there a simple way to run a python script every frame in an animation? AFAIK i could call mel procedures through the pre render mel options in the render settings, but how would i achieve something similar with python scripts?

thanks in advance,

01 January 2008, 02:32 PM
Hey you can use the python code as mel code. This is right out of the help docks in maya 8.5. Just search for python in the mel command reference if you wanna read more about it. Hope this helps.

MEL examples

python( "import sys" );

// Call some python that will return a list of values. Note that we are
// calling the python command with a single python statement. We have to
// do that if we want to get a result back
string $version[] = python( "sys.version_info" );

// The result will be an array of strings because one of the elements will
// contain a string. Extract the major and minor parts of the version number
int $major = int( $version[0] );
int $minor = int( $version[1] );

// You can do mult-statement Python scripts, but there won't be a return
// value
python( "import os\nprint os.environ[ 'MAYA_LOCATION' ]" );

01 January 2008, 07:10 PM
Pretty much the same as fritz8th's lower example, I simply make an expression that sets a call up to a python function every frame.

cmds.expression(n='expressionName', s='python(\"pythonFunctionName()\")')

and the actual call on its own (that can be added to the expression editor):



p.s, just make sure you import the python libraries in maya so that it knows what cmds is:
import maya.cmds as cmds

01 January 2008, 09:36 AM
thanks a lot, guys! works like a charm.

CGTalk Moderation
01 January 2008, 09:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.