layer Position to .txt (extract coordinates)

All things .jsx

Moderator: Paul Tuersley

Post Reply
Posts: 33
Joined: February 7th, 2005, 7:32 am

not tested on mac

This scripts allows you to export the current layer's positions through time to a .txt format (to export to a 3d app for instance)
It doesn't have a 'z' position nor does it allow you to select anchor points or rotation values - but I'll add it if needs be.

If no position keyframes are selected then all the position values during the comp length will be written to the text file


Code: Select all

// script created by mlk: Jan 2007 
// The script will write to a text file the x & y values of the layer position for every frame comprised in
// a selection of keyframes, or for the whole comp duration if no keyframes are selected

function timeToFrameNum(myTime){
	return Math.floor(myTime) * app.project.activeItem.frameRate + (myTime - Math.floor(myTime)) / (1/app.project.activeItem.frameRate);
function framesToTime(myTime){
	return myTime/app.project.activeItem.frameRate;
function timeToTimeCode(myTime){
	var framesN = myTime * app.project.activeItem.frameRate;
	fr = addZero(Math.round((myTime - Math.floor(myTime))/(1/app.project.activeItem.frameRate)));
	ho = addZero(Math.floor(myTime/3600));
	mi = addZero(Math.floor(myTime/60)-ho*60);
	se = addZero(Math.floor(myTime)-mi*60-ho*3600);
	return ho+":"+mi+":"+se+":"+fr;
function addZero(val){
		val = "0"+val;
	return val;
var myDisp = app.project.timecodeDisplayType;
app.project.timecodeDisplayType = TimecodeDisplayType.TIMECODE;
var pText = "Choose an output format using:\n%f (framenumber),%i (index, starts at 0) %t (SMTPE timecode), %x (x value), %y (y value), %l (linebreak) and any other character. Default output looks like '16: 230;22'";

if(app.project.activeItem != "null" && app.project.activeItem != null && app.project.activeItem != 0){
	if(app.project.activeItem.selectedLayers.length != 0){
		if(app.preferences.getPrefAsLong("Main Pref Section","Pref_SCRIPTING_FILE_NETWORK_SECURITY")){
			curLayer = app.project.activeItem.selectedLayers[0];
			var textName = "AEcoordinates.txt";
			var myTextFile = filePutDialog("Select a location to save your .txt file", textName, "TEXT txt");
			if(myTextFile == null){
				alert("You must choose a place to save the file");
				var formatString = prompt(pText,"%i: %x;%y%l");"w","TEXT","????");
				myKeys ="position").selectedKeys;
				if(myKeys.length != 0){
					strTime ="position").keyTime(myKeys[0]);
					endTime ="position").keyTime(myKeys[myKeys.length-1]);
					strTime = app.project.activeItem.workAreaStart;
					endTime = app.project.activeItem.workAreaStart + app.project.activeItem.workAreaDuration;
				var startLoop = timeToFrameNum(strTime);
				var endLoop = timeToFrameNum(endTime);
					var curTime = framesToTime(i);
					out = formatString.replace('%x',"position").valueAtTime(curTime,true)[0]);
					out = out.replace('%y',"position").valueAtTime(curTime,true)[1]);
					out = out.replace('%f',i);timeToTimeCode
					out = out.replace('%t',timeToTimeCode(curTime));
					out = out.replace('%i',i-startLoop);
					out = out.replace('%l','\n');
					write(Math.round((i-startLoop)/(endLoop-startLoop)*100,0)+"% done...");
			writeLn(endLoop-startLoop+" positions saved to file");
			writeLn("script written by mlk =)");
		} else {
			alert ("This script requires the scripting security preference to be set.\n" +
			"Go to the \"General\" panel of your application preferences,\n" +
			"and make sure that \"Allow Scripts to Write Files and Access Network\" is checked.");

		alert("Select a layer with 'position' keyframes");
	alert("Select a composition and a layer with 'position' keyframes");
app.project.timecodeDisplayType = myDisp;
Boom boom boom.
Posts: 15
Joined: December 7th, 2006, 10:39 pm

Very usefull! Thanks!
Posts: 2
Joined: January 11th, 2008, 12:13 pm

User avatar
Posts: 157
Joined: April 30th, 2007, 5:55 am
Location: United States, Ohio

How is this useful?

What 3D app is going to read that information?
Posts: 2
Joined: January 11th, 2008, 12:13 pm

Atomic wrote:How is this useful?

What 3D app is going to read that information?
I need information like this for an 'in house' GUI tool. I am planning to create the animation (layer by layer) in AFX, export TRS information as a document and import this information to our toolkit (which is still under development)

MASSIVE time saver - especially when it comes to iterative reworking
Posts: 62
Joined: September 5th, 2006, 3:45 am
Location: Chiswick, London, UK

Tasty!!! :D Nice touch on the animating GIF too.
Posts: 33
Joined: February 7th, 2005, 7:32 am

By extremely popular request (errr I mean the one mail I got) I'll try to add a much friendlier user interface, I need to code a bit to relax.

Boom boom boom.
Posts: 3
Joined: May 5th, 2010, 4:05 am

Hi, is there any way this script could be adjusted to output rotation values as well?
Much appreciated.
Posts: 8
Joined: January 31st, 2012, 12:23 am

i'm using aftereffect since in college but they never tell me that there's a script so handy like this. thanks sir. :D
Post Reply