0

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!

Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95
  • Its a escaping rule problem what OS and what shell are you using. Anyway you could simplify the problem a bit by using a python file that contains the text – joojaa Jan 03 '14 at 22:14

1 Answers1

1

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.

theodox
  • 12,028
  • 3
  • 23
  • 36
  • That worked editing the Maya.env, as we have a control machine, to send commands to 20 slaves, I needed to have this work just from one machine without editing other env files, so this worked just fine, thankyou for the suggestion! – Shannon Hochkins Jan 12 '14 at 22:19