Here we’re creating an empty render layer based on the “layername” argument, then we’re getting all the meshes in the scene. NewLyr = cmds.createRenderLayer(n=layername,empty=1,makeCurrent=1)Ĭmds.editRenderLayerMembers(layername,xforms) When we call this script, we’ll pass it a file to open, and a layer name to add. sys.argv just means the nth command line argument, so sys.argv is the first command-line argument when running the script (after calling for the script name, for example, by running mayapy.exe yourScript.py). The sys.argv and sys.argv are easy ways to pass variables to an external script. First, I’ll write the script that actually creates the layer and assigns objects. Let’s say I want this script to add a new render layer to several scenes, and add all meshes in each scene to that new layer. Again, I’m not going to go into a ton of detail about the module, it’s pretty complicated, but I’ll give a quick example of how I’m using it to return information from a Maya process when I am calling the script from Maya (or any other program, really). To do this, I used Python’s subprocess module. I needed to be able to process one file at a time, and then either return some useful information if the process is successful, or let me know if Maya crashes so I can avoid that file later on or at least mark it. Some commands are not available in standalone mode, especially anything to do with UI.Īnyways, while working on a script that is meant to process huge heaps of unsorted Maya files, I realized that crashes were going to be a frequent problem when opening ancient, broken scenes, so I couldn’t just load an instance of Maya in standalone mode from a script and let it run through everything in a loop. Once that’s done you can start scripting like normal, starting with import maya.cmds as cmds and working from there.
MAYA PYTHON LS IN GROUP HOW TO
There are other, more informative posts on how to get Python running in standalone mode (I learned a lot from this one in particular), but the gist of it is that you start by running /bin/mayapy.exe, and then initialize the Maya Python interpreter by calling the following function: Running scripts on lots of files at once is much faster if you’re running Maya in standalone (“batch”) mode. This sort of thing could be done in the usual windowed Maya interface, but this is slow and means the user has to sit there and watch Maya open a bunch of files, run operations and all that. There are countless articles out there listing the “best” ones if you Google “ best Python package 2017“.I’ve been working on some tools recently that open groups of Maya scenes in batch mode, running Python or MEL operations on each file (for example, to quickly add a render layer and apply materials to a large group of objects at once, or to get the names of all the references in a scene) and then either returning data or saving the file. It is mind numbing how many packages there are out there.
MAYA PYTHON LS IN GROUP DOWNLOAD
If there is something that you can not do, someone has written a library that you can download and use from the Python package index. If you look at the standard Python library, you realize the breadth of things you can do with Python out of the box.
MAYA PYTHON LS IN GROUP CODE
The truth is, the more readable your code is, the faster you and everyone else can work. One of Python’s main features is listed in PEP 20 – The Zen Of Python, which is “readability counts”. A Python interpreter was added in Maya 8.5 and it brought so many capabilities that MEL scripters had not previously had.