View Full Version : How to export cordinates of objects in Maya composition to a text file

01 January 2013, 03:39 PM

Let's say, I have 50 objects in my Maya composition and there is an animation with 3000 frames. All the objects are moving during the animation. I need to export the coordinates of objects as a list (sequence) with the order of frames in to a text files. What is the easiest way for this?

Thank you.

01 January 2013, 05:01 PM
this seems to work:

global proc Export_Frames_Coordinates ()
int $fileId;
string $animName = `file -q -shn -sn`;//gets the name of the scene
string $exportName = toNativePath(`workspace -q -fn` + "/MyExport/" + $animName + ".txt");//.txt file

string $allObj [] = `ls -l -sl`;//lists the selected objects

//gets the animation range
int $startFrame = `playbackOptions -q -minTime`;
int $endFrame = `playbackOptions -q -maxTime`;
currentTime -e $startFrame;
int $getCurrentTime = `currentTime -q`;

sysFile -makeDir `dirname ($exportName)`;//creates the file and the directory (if it doesn't already exists)
$fileId=`fopen $exportName "w"`;//open the txt file

for ( $getCurrentTime ; $getCurrentTime < ($endFrame+1) ; $getCurrentTime + 1) //let's run through the animation
string $frame = $getCurrentTime;

fprint $fileId ("frame " + $frame + "\n");//writes current frame in the file

for ($each in $allObj)
float $coordinates [3] = `xform -q -ws -t $each`;

fprint $fileId ("coordinates of " + $each + "\n");
fprint $fileId ($coordinates [0] + "|" + $coordinates [1] + "|" + $coordinates [2] + "|" + "\n");//writes coordinates
currentTime -e ($getCurrentTime + 1) -u true;
$getCurrentTime = `currentTime -q`;

fclose $fileId;//closes the file

CGTalk Moderation
01 January 2013, 05:01 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.