سؤال

I need to run a batch render command via terminal, and use the mel callbacks, to run a python module.

The terminal command I'm using is this:

Render -preRender "python(\"import sys\nsys.path.append(\"/Volumes/raid/farm_script/\")\nfrom run_os import Farm\nFarm()\")" "/path/to/scene.mb";

Essentially, the command in the escaped string should be read like this:

import sys
sys.path.append("/Volumes/raid/farm_script/")
from run_os import Farm
Farm()

In Maya's script editor, running the above command in a python tab, does print out data.

Running the exact same script, in a mel tab but wrapped in a python function, also works fine!

In the 'Farm' class located under /Volumes/raid/farm_scripts/run_os.py, I have this tiny little script.

class Farm():
    def __init__(self):
        self.run()
    def run(self, *args):
        print "=== TEST ===\n"

Which I'm seeing my print test in the script editor, however running this command, using the MEL callbacks in the batch render terminal, leaves me with an 'unexpected indentation error', after vigorous testing, I've found that it's coming from the from run_os import Farm, so my question is, why does this line create the indentation error, there's no indentation at all as i'm using the \n (newline) flag, unless I'm seriously mistaken!

هل كانت مفيدة؟

المحلول

It's probably because you're asking a shell command to run an argument which includes a newline. Try putting the script into a mel file (in the rendering machine's script dir) and then just sourcing that. Or, failing that, make sure that the rendering machine has the correct sys path by editing your environment vars or setting it in Maya.env.

If things are more complex than that you can do the whole thing from Python by starting up a Maya.standalone and controlling it from the outside. If you go that route you can add a simple server that uses sockets or wsgi1 to accept commands over a network or locally.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top