AE ENHANCERS

Expressions/Scripts/Presets
It is currently Sat Nov 01, 2014 5:59 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: layer Position to .txt (extract coordinates)
PostPosted: Tue May 22, 2007 10:38 am 
Offline

Joined: Mon Feb 07, 2005 7:32 am
Posts: 29
not tested on mac
extractcoordinates.jsx

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


Image

Code:
// script created by mlk: mlkdesign@gmail.com 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){
   if(val<10){
      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");
         }else{
            var formatString = prompt(pText,"%i: %x;%y%l");
            myTextFile.open("w","TEXT","????");
            myKeys = curLayer.property("position").selectedKeys;
            if(myKeys.length != 0){
               strTime = curLayer.property("position").keyTime(myKeys[0]);
               endTime = curLayer.property("position").keyTime(myKeys[myKeys.length-1]);
            }else{
               strTime = app.project.activeItem.workAreaStart;
               endTime = app.project.activeItem.workAreaStart + app.project.activeItem.workAreaDuration;
            }
            var startLoop = timeToFrameNum(strTime);
            var endLoop = timeToFrameNum(endTime);
            for(i=startLoop;i<=endLoop;i++){
               var curTime = framesToTime(i);
               out = formatString.replace('%x',curLayer.property("position").valueAtTime(curTime,true)[0]);
               out = out.replace('%y',curLayer.property("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');
               myTextFile.write(out);
               clearOutput();
               write(Math.round((i-startLoop)/(endLoop-startLoop)*100,0)+"% done...");
            }
         clearOutput();
         writeLn(endLoop-startLoop+" positions saved to file");
         writeLn("script written by mlk =)");
         myTextFile.close();
         }
      } 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.");
      }

   }else{
      alert("Select a layer with 'position' keyframes");
   }
}else{
   alert("Select a composition and a layer with 'position' keyframes");
}
app.project.timecodeDisplayType = myDisp;

_________________
Boom boom boom.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 11:42 am 
Offline

Joined: Thu Dec 07, 2006 10:39 pm
Posts: 15
Very usefull! Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 6:43 am 
Offline

Joined: Fri Jan 11, 2008 12:13 pm
Posts: 2
AWESOME! 8)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 6:40 am 
Offline
User avatar

Joined: Mon Apr 30, 2007 5:55 am
Posts: 157
Location: United States, Ohio
How is this useful?

What 3D app is going to read that information?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 6:55 am 
Offline

Joined: Fri Jan 11, 2008 12:13 pm
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: layer Position to .txt (extract coordinates)
PostPosted: Mon Feb 11, 2008 4:18 am 
Offline

Joined: Tue Sep 05, 2006 3:45 am
Posts: 62
Location: Chiswick, London, UK
Tasty!!! :D Nice touch on the animating GIF too.


Top
 Profile  
 
 Post subject: Re: layer Position to .txt (extract coordinates)
PostPosted: Fri Apr 11, 2008 8:22 am 
Offline

Joined: Mon Feb 07, 2005 7:32 am
Posts: 29
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.

matt

_________________
Boom boom boom.


Top
 Profile  
 
 Post subject: Re: layer Position to .txt (extract coordinates)
PostPosted: Mon May 24, 2010 7:08 pm 
Offline

Joined: Wed May 05, 2010 4:05 am
Posts: 3
Hi, is there any way this script could be adjusted to output rotation values as well?
Much appreciated.


Top
 Profile  
 
 Post subject: Re: layer Position to .txt (extract coordinates)
PostPosted: Wed Feb 01, 2012 1:56 am 
Offline

Joined: Tue Jan 31, 2012 12:23 am
Posts: 8
i'm using aftereffect since in college but they never tell me that there's a script so handy like this. thanks sir. :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group