some handy Maya file commands
some basic file and directory path operation commands
How to query currently opened scene name?
How to find directory path of the currently opened scene?
dirname(`file -q -sceneName`);
How to find path to your default projects directory?
string $path[]= `internalVar -uwd`;
uwd flag is short for user work directory
How to make directory thru mel?
depends on where you want to make first line can vary.
i will illustrate how to make folder in maya/scene folder
$currentFilePath = dirname(`file -q -sceneName`);
$folder = $currentFilePath + "/my_folder";
sysFile -makeDir $folder ;
How to export obj using file command?
for example i will use above location to create another folder name my_obj_folder
$sel = `ls -sl`;
$currentFilePath = dirname(`file -q -sceneName`);
$objfolder = $currentFilePath + "/my_obj_folder";
sysFile -makeDir $objfolder ;
string $objpath = $objfolder + "/" + $sel[0] + ".obj";
file -typ "OBJ" -pr -es $objpath;
if you want to make folder name as selected object name in maya then replace line 3 in above script with this $objfolder = $currentFilePath + "/" + $sel[0];
$sel = `ls -sl`;
$currentFilePath = dirname(`file -q -sceneName`);
$objfolder = $currentFilePath + "/" + $sel[0];
sysFile -makeDir $objfolder ;
string $objpath = $objfolder + "/" + $sel[0] + ".obj";
file -typ "OBJ" -pr -es $objpath;
How to open a file using fileDialog mel command?
string $filename = `fileDialog -m 0 -directoryMask "/home/username/maya/scenes/*.ma"`;
file -o $filename;
i have used fileDialog and file mel command here
you can replace path with whatever path you are working on.
m flag in the first line stands for mode. 0 is for opening the file.
note: if u have unsaved file opened when you run the script it will give u error.