PDA

View Full Version : applescript & maya


jschleifer
03-09-2003, 04:17 AM
Hey guys,

I know I used applescript to tell maya to do stuff before, but now for the life of me I can't figure out how to do it again, and there's no documentation on it.

Does anyone know how to send commands to Maya through applescript?

what about fcheck?

cheers!
-jason

mark_wilkins
03-09-2003, 05:46 AM
Hey Jason:

I don't have Maya installed, so I can't give you much more than this, but have you tried opening up the Script Editor, choosing File > Open Dictionary... and choosing Maya off the list?

You should get a window that lists all of the types of commands and data objects that Maya supports.

Then you just make a script that contains

tell application "Maya 4.5"
<commands>
end tell

-- Mark

jschleifer
03-09-2003, 09:35 AM
Heya!

yep, already checked that.. Maya doesn't show up in the dictionary.. I'm able to get it to open (activate), but after that.. Ican't do much except exit. :)

-jason

mark_wilkins
03-09-2003, 09:41 AM
was your earlier experience with 3.5? Is it possible they took support out?

You could always fire Maya batch commands off on the command line through Terminal, but depending on what you're doing that may not be a good solution. :D

-- Mark

jschleifer
03-09-2003, 09:47 AM
I don't think support was taken out.. it was one of the big marketing pushes.. better support for AppleScript.

I remember getting it to work before, but it was on another machine and I don't have access to the applescript that I wrote.. d'oh!

the nice thing about applescript is that you can tell the app to do anything.. unlike on linux where you have to go through the command port.

Pretty handy, really..

:)
-jason

bigfatMELon
03-09-2003, 06:46 PM
Try this:

tell application "Maya"
execute "sphere;"
execute "print \"see, I told you it works.\";"
end tell

-jl

bigfatMELon
03-09-2003, 06:48 PM
Oh, and via QuicKeys from within your text editor, this is handy for development:

tell application "Maya"
execute "scriptEditorInfo -ch;"
execute "source myScript;"
execute "myScript;"
end tell

-jl

jschleifer
03-09-2003, 07:55 PM
bigfatmelon.. you're a legend. :)

thanks!:beer:

bigfatMELon
03-09-2003, 08:13 PM
heh.

Hey, if you're doing appleScript stuff you might be interested in getting Maya to "tell" other apps to do stuff as well. The following scripts illustrates a method for speaking to other apps from MEL. It tells the Finder to reveal your scripts folder.


----begin script mahem----

proc string stringPopLastChar (string $item){
string $returnString;

$returnString = `substring $item 1 (size($item) -1)`;

return $returnString;
}


global proc string stringPopFirstChar (string $item){
string $returnString;

$returnString = `substring $item 2 (size($item))`;

return $returnString;
}


proc string stringReplaceDelimiter (string $item, string $wordChar, string $replace){
string $tokenList[];
string $returnString;

tokenize $item $wordChar $tokenList;

if (`stringFirstChar $item` == $wordChar)
{$returnString += $replace;}

for ($x in $tokenList){
$returnString += ($x + $replace);
}

if (`stringLastChar $item` != $wordChar)
{$returnString = `stringPopLastChar $returnString`;}

return $returnString;
}


global proc int stringContains (string $theString, string $item){
string $matchString = ($item + "+");
int $returnInt = 0;

if (`match $matchString $theString` == $item){
$returnInt = 1;
}

return $returnInt;
}



global proc revealScripts (){
string $env = `getenv MAYA_SCRIPT_PATH`;
string $scriptPaths[];
string $fileName = "revealScript.txt";
string $folder, $path, $revPath, $applePath, $cmd;
int $fileID;

tokenize $env ";" $scriptPaths;

for ($x in $scriptPaths){
if (`stringContains $x "maya/scripts"`){
$revPath = $x;
}
}

if ($revPath != ""){
//...build the path to the temporary script
$folder = `workspace -q -rd`;
$path = ($folder + $fileName);

//...build the path that applescript needs to reveal
$applePath = `stringReplaceDelimiter $revPath "/" ":"`;
$applePath = `stringPopFirstChar $applePath`;

//...build the script
$fileID = `fopen $path "w"`;
fprint $fileID "tell application \"Finder\"\n";
fprint $fileID "activate\n";
fprint $fileID ("open \"" + $applePath + "\"\n");
fprint $fileID "set first window's current view to column view\n";
fprint $fileID "end tell\n";

fclose $fileID;

//...run the script
$cmd = ("/usr/bin/osascript " + $path);
system ($cmd);
}
else{
error ("script path could not be determined.");
}
}

-jl

CGTalk Moderation
01-14-2006, 02:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.