getting list of camera or render globals from maya scene file without opening scene in maya

StackOverflow https://stackoverflow.com/questions/13757962

  •  05-12-2021
  •  | 
  •  

سؤال

is it possible with python to read a maya scene file without opening and get list of camera's or render globals setting or perform some operations on it. I need this so that if their are multiple scene files I do not have to open each maya scene and just tweak it from a python script, I would really appreciate if some one can show how to start rest I will do myself...

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

المحلول

Its possible, may just not be practical. A Maya ASCII file is pretty trivial to parse. A Maya binary file not so much. It may be a bit premature to discuss there matters.

First things first. Maya does offer a batch mode, the batch mode does not use up a full license. It still opens a full Maya environment but no GUI. This is the perfect platform to inject scripts. It doesn't really fulfill your request of not opening Maya but it fulfills all other requirements. There are a few ways for using this batch mode. But mostly it boils down to two general methods.

Method 1, using mayabatch: The mayaXX/bin/ directory contains a command called mayabatch. You can simply call this from a cmd/shell batch file/shellscript. This is a extremely simple way of calling existing scripts. Assuming mayabatch is in the path of your environment and your script is in Maya script path. Lets assume for simplicity that your script looks as follows (demo.py):

import maya.cmds as cmd

def func():
    print cmd.ls()

# we want this to execute on import
func()

Now calling this for one file under windows would look as following:

mayabatch -command "python(""import demo"") " -file filename.ma

calling this over all Maya in the current folder files would then be simply:

for %i in (*.ma) do mayabatch -command "python(""import demo"") " -file %i

The quoting rules are a bit different on mac and Linux but should be easy to find. reefer to the manual of your shell.

Method 2, using mayapy and standalone:

Now you can also directly call the python script with mayapy. Its located in the same directory as mayabtach. Tough the standalone can be called form other python interpreters too if you include Maya modules in the system path. Now the script must be a bit changed so it does the same thing (demo_direct.py):

#init maya
import maya.standalone
maya.standalone.initialize( name='python' )
import maya.cmds as cmd
import glob

def func():
    print cmd.ls(shapes=True)

for file in glob.glob('*.m[ab]'):
    cmd.file( file, o=True )
    func()

call this form command line with:

mayapy demo_driect.py

Neither of these methods load Mayas graphical user interface. So you can not call stuff like playblast etc. Since they rely on a GUI, and thus a full Maya license. Nothing says you can not do a similar load loop in the GUI as above.

Then for the methods without actually loading Maya. This is a bit tricky. Doing this is not necessarily worth it since the batch nodes are pretty fast as they don't eventuate everything on load. A sample script that parses a Maya ASCII file for frame ranges. You might find it useful. See following post. For Maya binary files there is a python module in cgKit that will help you read Maya binary chunks. Unfortunately it doesn't do anything for understanding the data.

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