// jdSmartBaker.jsx // Creatogether Smart Baker // // Created by Dan Borufka and Jake Rathmanner on 2011-04-24. // Copyright (c) 2010 Creatogether. All rights reserved. // // Bake properties with detection of gaps and linear interpolation // in Adobe(R) After Effects(R) CS4 or later. Use at your // own risk. Brought to you by Jake and Dan of // creatogether.com // // Notes: // This script allows you to bake properties of layers // with consideration of gaps and linear interpolation. // The Detection threshold defines how generous // the detection of gaps and interpolation operates. // // For any further info // visit us at http://www.creatogether.com/jd-smart-baker // // You can use this script as a dockable panel by // placing it in a ScriptUI Panels subfolder of the // Scripts folder, and then choosing the jdSmartBaker.jsx // from the Window menu. var scriptName = "JD Smart Baker"; // *** function to round a number to "digits" numbers - e.g. round(5.4257, 2) returns 5.42 *** function round(nr, digits) { digits = Math.pow(10, digits); return Math.round(nr*digits)/digits; } // *** simple function to calculate linear interpolation *** function linear(delta, min, max) { return min + (max - min) * delta; } // *** main bake-repair engine *** function smartBake(pal) { var actItem = app.project.activeItem; var selection = actItem.selectedLayers[0]; var thresh = 10-parseInt(pal.grp.threshold.sldr.value); var expr = ""; var props = selection.selectedProperties; var A, B, C, delta, same; if(props.length == 0 || app.project == null || actItem == null || !(actItem instanceof CompItem) || actItem.selectedLayers.length == 0) alert("You first must select the properties of a layer to be baked inside a comp."); else { app.beginUndoGroup("JD Smart Baker"); for(var j in props) { var prop = props[j]; if(!prop.expressionEnabled) { if(prop.expression != "") expr = prop.expression; prop.expression = "value;"; prop.expressionEnabled = true; } app.executeCommand(app.findMenuCommandId("Convert Expression to Keyframes")); // run built-in baking-engine for(var i=prop.numKeys; i>0; i--) { same = true; // are the two adjacent keyframes (current key-1 and current key+1) the same? A = prop.keyValue(i); // current keyframe B = (i > 1 ? prop.keyValue(i-1) : false); // previous keyframe C = (i < prop.numKeys ? prop.keyValue(i+1) : false); // next keyframe - replace false by B // to automatically remove the last key as well if necessary if(i>1 && i