// After Effects script - import property keyframes from text file // By Vincent Rubinetti // 08 - 12 - 2009 var pointSeparator = "\n"; var xySeparator = " "; var project = app.project; if (project) { var myComp = app.project.activeItem; if (myComp != null && (myComp instanceof CompItem)) { var selectedLayers = myComp.selectedLayers; if(selectedLayers.length == 1) { var myLayer = selectedLayers[0]; var selectedProps = myLayer.selectedProperties; if(selectedProps.length == 3) { alert("Select a text file with data points"); var myFile = File.openDialog ("Select text file with data points"); if (myFile) { var fileOK = myFile.open("r","TEXT","????");} if (fileOK) { var undoStr = "Import Keyframes"; app.beginUndoGroup(undoStr); var myLayer = selectedLayers[0]; var myText = myFile.read(); var points = myText.split(pointSeparator); var xyArray = new Array(); var vertexArray = new Array(); var xmin, ymin, xmax, ymax; for(var i = 0; i < points.length; i++) { xyArray = points[i].split(xySeparator); if (xyArray.length == 2 && !isNaN(parseFloat(xyArray[0])) && !isNaN(parseFloat(xyArray[1]))) { xyArray[0] = parseFloat(xyArray[0]); xyArray[1] = parseFloat(xyArray[1]); if (i == 0) { xmin = xyArray[0]; ymin = xyArray[1]; xmax = xyArray[0]; ymax = xyArray[1]; } else { if (xyArray[0] > xmax) {xmax = xyArray[0];} if (xyArray[0] < xmin) {xmin = xyArray[0];} if (xyArray[1] > ymax) {ymax = xyArray[1];} if (xyArray[1] < ymin) {ymin = xyArray[1];} } vertexArray[i] = xyArray; } else {break;} } var xoffset, yoffset; var askScale, xscale, yscale; if (confirm("Maintain aspect ratio?")) { askScale = parseFloat(prompt("Scale factor (1 for original size, 2 for twice original size, etc; -1 to fit comp size):", 1)); if (askScale < 0) { xscale = myComp.width/(xmax-xmin); yscale = myComp.height/(ymax-ymin); if (xscale < yscale) {yscale = xscale;} else {xscale = yscale;} } else { xscale = askScale; yscale = askScale; } } else { askScale = parseFloat(prompt("X scale factor (1 for original size, 2 for twice original size, etc; -1 to fit comp size):", 1)); if (askScale < 0) {xscale = myComp.width/(xmax-xmin);} else {xscale = askScale;} askScale = parseFloat(prompt("Y scale factor (1 for original size, 2 for twice original size, etc; -1 to fit comp size):", 1)); if (askScale < 0) {yscale = myComp.height/(ymax-ymin);} else {yscale = askScale;} } xoffset = parseFloat(prompt("X offset:", 0)); yoffset = parseFloat(prompt("Y offset:", 0)); var timeArray = new Array(); var xArray = new Array(); var yArray = new Array(); for (i = 0; i < vertexArray.length; i++) { vertexArray[i][0] = (vertexArray[i][0])*xscale; vertexArray[i][1] = (vertexArray[i][1])*yscale; vertexArray[i][0] += xoffset; vertexArray[i][1] += yoffset; timeArray[i] = i*myComp.frameDuration; xArray[i] = vertexArray[i][0]; yArray[i] = vertexArray[i][1]; } selectedProps[1].setValuesAtTimes(timeArray,xArray); selectedProps[2].setValuesAtTimes(timeArray,yArray); alert("STATS \n Points: "+vertexArray.length+" \n X Scale: "+xscale+" \n Y Scale: "+yscale+" \n Center X: "+((myComp.width/2)+xoffset)+" \n Center Y: "+((myComp.height/2)+yoffset)); myFile.close(); app.endUndoGroup(); } } else {alert("Error opening text file");} } else {alert("Exactly two properties must be selected");} } else {alert("Exactly one layer must be selected");} } else {alert("No comp");} } else {alert("No project");}