Some other useful resources are, Chad Vernon’s blog on python scripting in Maya.
![maya python ls command maya python ls command](https://cdnb.artstation.com/p/media_assets/images/images/000/682/965/large/7f92ef4a67bd9440f275d45680888819.jpg)
We don't really need to save the Maya file) # Save the file (I have commented this out, since it sometimes causes errors. In this example, I have defined a procedure to get the poly/triangle count of a Maya scene and print that into a text file and save it. def FindObjectsWithNoUVShells(): ObjectsWithNoUVShells OldSel mc.ls (slTrue) Geo mc.ls (typmesh) for Obj.
of Triangles: " + str (polys) + "\n")Ĭmds.file(fileToOpen, force=True, open=True) Eg: mayapyPolys = cmds.polyEvaluate (triangle=True) # proc to get the scene poly/triangle count # Other procedures can be defined here and then called in the main program In cmd line, go to the folder where the script is savedĮg: mayapy scene_stats.py "D:/work/./scenes/billards_table.ma" "C:/./output.txt" Make sure that Path (in env variables) is set to "C:\Program Files\Autodesk\Maya2014\bin" You can add procedures to get a list of all materials and lights in a scene and print that out too.Įxample python script showing how mayapy can be used to run scripts from cmd line, without launching Maya In this example, I have defined a procedure to get the poly/triangle count of a Maya scene and print that into a text file and save it. I have a very simple python script here, which you can use as a skeleton and add your own procedures. In my case, it is this: “C:\Program Files\Autodesk\Maya2014\bin”ģ. Since mayapy is in the /bin folder, locate it on your computer and add it’s path to the “Path” environment variable. #continue with your script, using the normalĢ. In your Python script, include the following
It is much faster when running Maya in standalone and using /bin/mayapy.exeġ. The result is a very awkward and unpythonic syntax which does not take advantage of python's strengths - particulary, a flexible, object-oriented design. Maya's command module is a direct translation of mel commands into python commands. This is very slow if you launch Maya, open the file and execute the script. PyMEL makes python scripting with Maya work the way it should. I have been developing some tools and scripts where I had to open Maya scenes in batch mode, run a Python script on it and log results in a text file.
![maya python ls command maya python ls command](https://i.ytimg.com/vi/13KBklf9ElY/maxresdefault.jpg)
Recently I discovered the power and flexibility of mayapy interpreter.