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

Code: Select all
// 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;