Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
berniebernie
Topic Author
Posts: 32
Joined: Mon Feb 07, 2005 7:32 am
Contact:

layer Position to .txt (extract coordinates)

Tue May 22, 2007 10:38 am

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

// 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.
 
lya98
Posts: 15
Joined: Thu Dec 07, 2006 10:39 pm

Wed May 30, 2007 11:42 am

Very usefull! Thanks!
 
DecWest
Posts: 2
Joined: Fri Jan 11, 2008 12:13 pm

Sat Jan 12, 2008 6:43 am

AWESOME! 8)
 
User avatar
Atomic
Posts: 157
Joined: Mon Apr 30, 2007 5:55 am
Location: United States, Ohio

Mon Jan 14, 2008 6:40 am

How is this useful?

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

Mon Jan 14, 2008 6:55 am

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
 
Darkmoon_UK
Posts: 62
Joined: Tue Sep 05, 2006 3:45 am
Location: Chiswick, London, UK
Contact:

Re: layer Position to .txt (extract coordinates)

Mon Feb 11, 2008 4:18 am

Tasty!!! :D Nice touch on the animating GIF too.
 
berniebernie
Topic Author
Posts: 32
Joined: Mon Feb 07, 2005 7:32 am
Contact:

Re: layer Position to .txt (extract coordinates)

Fri Apr 11, 2008 8:22 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.

matt
Boom boom boom.
 
kilopop
Posts: 3
Joined: Wed May 05, 2010 4:05 am

Re: layer Position to .txt (extract coordinates)

Mon May 24, 2010 7:08 pm

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

Re: layer Position to .txt (extract coordinates)

Wed Feb 01, 2012 1:56 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

Who is online

Users browsing this forum: No registered users and 3 guests