How to export cordinates of objects in Maya composition to a text file

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  01 January 2013
How to export cordinates of objects in Maya composition to a text file

Hello,

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

Last edited by depakeen : 01 January 2013 at 05:04 PM.
 
  01 January 2013
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:03 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.