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.
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...