Book Image

Maya Programming with Python Cookbook

By : Adrian Herbez
Book Image

Maya Programming with Python Cookbook

By: Adrian Herbez

Overview of this book

Maya is a 3D graphics and animation software, used to develop interactive 3D applications and games with stupendous visual effects. The Maya Programming with Python Cookbook is all about creating fast, powerful automation systems with minimum coding using Maya Python. With the help of insightful and essential recipes, this book will help you improve your modelling skills. Expand your development options and overcome scripting problems encountered whilst developing code in Maya. Right from the beginning, get solutions to complex development concerns faced when implementing as parts of build.
Table of Contents (17 chapters)
Maya Programming with Python Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Using the fileDialog2 command to navigate the file system


Loading and saving files will almost always require prompting the user for a file location. In this example, we'll look at how to do that. We'll also see how to work with directories, including creating new ones.

We'll create a script that will allow the user to browse the files in a customData folder within the current project directory. If that folder doesn't exist, it will be created the first time the script is run.

How to do it...

Create a new file and add the following:

import os
import maya.cmds as cmds

def browseCustomData():

    projDir = cmds.internalVar(userWorkspaceDir=True)
    
    newDir = os.path.join(projDir, 'customData')

    if (not os.path.exists(newDir)):
        os.makedirs(newDir)

    cmds.fileDialog2(startingDirectory=newDir)


browseCustomData()

You'll be presented with a file browser dialog. And, while the dialog won't actually do anything just yet, if you check your project directory, you'll find that it...