// rd_Duplink.jsx // Copyright (c) 2006-2013 Jeffrey R. Almasol. All rights reserved. // portfolio: www.redefinery.com // // Name: rd_Duplink // Version: 3.2 // // Description: // This script displays a palette with controls for creating linked instances of a // selected layer's properties. These links are made via pick-whipped expressions, so // only those properties that can use expressions can be linked. Use this script to // create duplicates or "instances" of a layer, which allow you to change the main layer // and have its instance layers update as well. // // Prerequisites: // -- This script requires After Effects CS4 or later. // -- Make sure the "Enable JavaScript Debugger" option (in the General Preferences // dialog box) is not selected. Otherwise, the script might stop with an 'After // Effects error: Can not “set expression” with this property, because the property // or a parent property is hidden.' error message. // // Usage: // 1. Select a layer. // 2. Specify the layer properties to link (Link list), and if the Position transform // property should be linked. Don't link Position if you want to reposition the // linked instances immediately after creating them. // 3. Specify the number of instances to create, and if they should be selected // immediately (and original layer deselected). // 4. Click the Create Linked Instances button. // // The specified number of instances are created and linked to the original layer. // // Notes: // -- Properties that cannot use expressions, custom effect settings, cannot be // linked. // // Legal Notices: // This script is provided "as is," without warranty of any kind, expressed or implied. // In no event shall the script's author be held liable for any damages arising in any // way from the use of this script. // // This script is excerpted from Adobe After Effects CC Visual Effects and Compositing Studio Techniques by Mark Christiansen. // (c) 2013. Published by Adobe Press. All rights reserved. A complete chapter on scripting // by Jeff Almasol is included with the book. Additional scripts are available at // http://aescripts.com/rd-studio-techniques/ (function rd_Duplink(thisObj) { // Globals // Store all constants in a global object, for consolidated organization in ExtendScript Toolkit's Data Browser var rd_DuplinkData = new Object(); rd_DuplinkData.scriptName = "rd: Duplink"; rd_DuplinkData.scriptTitle = rd_DuplinkData.scriptName + " v3.2"; // Various text strings are defined as associative arrays (dictionaries) to support localizability via rd_localize() function rd_DuplinkData.strFeature = {en: "Link:"}; rd_DuplinkData.strFeatureOpts = {en: '["Layer - All Linkable Properties", "Layer - Transform", "Layer - Material Options", "Layer - Masks", "Layer - Effects"]'}; rd_DuplinkData.strLinkPosTransform = {en: "Link Position transform property"}; rd_DuplinkData.strCopies = {en: "Instances:"}; rd_DuplinkData.strSelectInstances = {en: "Select instances, deselect original"}; rd_DuplinkData.strLink = {en: "Create Linked Instances"}; rd_DuplinkData.strHelp = {en: "?"} rd_DuplinkData.strErrNoCompSel = {en: "Cannot perform operation. Please select or open a single composition in the Project panel, and try again."}; rd_DuplinkData.strErrNoLayerSel = {en: "Cannot perform operation. Please select at least one layer, and try again."}; rd_DuplinkData.strErrMoreThan1Selection = {en: "To create layer instances, select only one layer, and try again."}; rd_DuplinkData.strMinAE90 = {en: "This script requires Adobe After Effects CS4 or later."}; rd_DuplinkData.strHelpText = { en: "Copyright (c) 2006-2013 Jeffrey R. Almasol. All rights reserved.\n" + "portfolio: www.redefinery.com\n\n" + "Description:\n" + "This script displays a palette with controls for creating linked instances of a selected layer's properties. These links are made via pick-whipped expressions, so only those properties that can use expressions can be linked. Use this script to create duplicates or \"instances\" of a layer, which allow you to change the main layer and have its instance layers update as well.\n\n" + "Prerequisites:\n" + " -- This script requires After Effects CS4 or later.\n" + " -- Make sure the \"Enable JavaScript Debugger\" option (in the General Preferences dialog box) is not selected. Otherwise, the script might stop with an 'After Effects error: Can not “set expression” with this property, because the property or a parent property is hidden.' error message.\n\n" + "Usage:\n" + " 1. Select a layer.\n" + " 2. Specify the layer properties to link (Link list), and if the Position transform property should be linked. Don't link Position if you want to reposition the linked instances immediately after creating them.\n" + " 3. Specify the number of instances to create, and if they should be selected immediately (and original layer deselected).\n" + " 4. Click the Create Linked Instances button.\n\n" + "The specified number of instances are created and linked to the original layer.\n\n" + "Notes:\n" + " -- Properties that cannot use expressions, such as custom effect settings, cannot be linked.\n\n" + "Legal Notices:\n" + "This script is provided \"as is,\" without warranty of any kind, expressed or implied. In no event shall the script's author be held liable for any damages arising in any way from the use of this script.\n\n" + "This script is excerpted from Adobe After Effects CS6 Visual Effects and Compositing Studio Techniques by Mark Christiansen. (c) 2013. Published by Adobe Press. All rights reserved. Additional scripts and a complete chapter on scripting by Jeff Almasol are included in the book, available at http://www.peachpit.com/store/adobe-after-effects-cs6-visual-effects-and-compositing-9780321834591" }; // rd_localize() // // Description: // This function localizes the given string variable based on the current locale. // // Parameters: // strVar - The string variable's name. // // Returns: // String. // function rd_localize(strVar) { return strVar["en"]; } // rd_Duplink_buildUI() // // Description: // This function builds the user interface. Coordinates of various controls are relative // to others so that they can adapt if spacing is adjusted. // // Parameters: // thisObj - Panel object (if using a dockable panel) or Window object (if using a traditional palette). // // Returns: // Panel or Window object representing the built user interface. // function rd_Duplink_buildUI(thisObj) { var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", rd_DuplinkData.scriptName, undefined, {resizeable:true}); if (pal !== null) { var res = """group { orientation:'column', alignment:['fill','top'], alignChildren:['fill','top'], header: Group { alignment:['fill','top'], margins:[0,0,0,5], title: StaticText { text:'""" + rd_DuplinkData.scriptName + """' }, }, link1: Group { feature: StaticText { text:'""" + rd_localize(rd_DuplinkData.strFeature) + """' }, featureOpts: DropDownList { preferredSize:[-1,20] }, }, link2: Group { alignment:['left','top'], linkPos: Checkbox { text:'""" + rd_localize(rd_DuplinkData.strLinkPosTransform) + """', value:true }, }, inst1: Group { copiesLbl: StaticText { text:'""" + rd_localize(rd_DuplinkData.strCopies) + """' }, copies: EditText { text:'1', characters:5, preferredSize:[-1,20] }, }, inst2: Group { alignment:['left','top'], selInstances: Checkbox { text:'""" + rd_localize(rd_DuplinkData.strSelectInstances) + """', value:true }, }, footer: Group { alignment:['fill','top'], margins:[0,5,0,0], helpBtn: Button { text:'""" + rd_localize(rd_DuplinkData.strHelp) + """', alignment:['left','top'], maximumSize:[30,20] }, linkBtn: Button { text:'""" + rd_localize(rd_DuplinkData.strLink) + """', alignment:['right','top'], preferredSize:[-1,20] }, }, }"""; pal.grp = pal.add(res); var items = eval(rd_localize(rd_DuplinkData.strFeatureOpts)); for (var i=0; i 1) for (var i=2; i<=copies; i++) { newLayer = followers[0].duplicate(); newLayer.moveAfter(followers[followers.length-1]); newLayer.name = leader.name + " Instance " + i; followers[followers.length] = newLayer; } // Set selection to the instance layers, if requested if (selInstances) { leader.selected = false; for (var i=0; i