Book Image

Practical Maya Programming with Python

By : Robert Galanakis
Book Image

Practical Maya Programming with Python

By: Robert Galanakis

Overview of this book

Table of Contents (17 chapters)
Practical Maya Programming with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Practical uses and improvements


We will close out the chapter by describing various uses for our automation system, as well as a few improvements.

Batch processing using Maya

The most obvious application for the automation system is batch processing. The following simple script will go through all files in the current directory, delete all unknown nodes, and save the file to a new path. It will print out the result of the processing for each file, and skip over errors.

import os
import mayaserver.client as mayaclient

execstr = """import pymel.core as pmc
pmc.openFile(%r, force=True)
for item in pmc.ls(type='unknown'):
    if item.exists():
        pmc.delete(item)
pmc.system.saveAs(%r)"""

def process(socket, path):
    newpath = os.path.splitext(path)[0] + '_clean.ma'
    mayaclient.sendrecv(
        socket, ('exec', execstr % (path, newpath)))

if __name__ == '__main__':
    sock = mayaclient.create_client(mayaclient.start_process())
    paths = [p for p in os.listdir(os.getcwd())
     ...