// Selected_Comps_Changer.jsx // version 1.9 by CR Green (www.crgreen.com) // (v1.9 adds a close function to the ok button, which, previous to AE CS3, closed automatically) // A Green Digital Entrustment // Requested by Yorgo Alexopoulos The Great //globals: //// var weCanCloseWindow = true; var win = new Window('dialog', 'Change Selected Comps',[300,100,800,560]); var w = buildUI(); var probStr = ""; ///////////// start(); function bigHelp() { var bigHelpTxt = "Perhaps I can help ...\rIf you want to change a setting in your selected comps, enter something in a field, or click a \"Do\" checkbox. " + "All fields after the first two must be numbers.\rRegarding name changing:\rFor search and replace, enter text in both of the top two fields; " + "If you want to add text to the beginning or end of the comp names, uncheck the \"do search\" checkbox, enter the text to be added in the " + "second field, and choose the appropriate radio button to the right.\rNon-numbers in fields which require numbers will result in that comp setting " + "being ignored, and those errors are reported."; alert(bigHelpTxt); } function doAbout() { var aboutTxt = "Selected_Comps_Changer (version 1.8)\rThis script was written for Yorgo Alexopoulos by Christopher R. Green, at Yorgo's request for something more-or-less like it. " + "It is one of many scripts available from crgreen.com. Feel free to give Chris feedback."; alert(aboutTxt); } function start() { if (app.project != null) { if (app.project.items.length < 2) { alert("Please select at least two comps."); } else { var everyItem = app.project.items; var thisManySelComps = 0; for (var i = everyItem.length; i >= 1; i--) { item = everyItem[i]; if ((item instanceof CompItem) && item.selected) { thisManySelComps++; } }//for (var i = items.length; i >= 1; i--) //finally ... if ( (w != null) && (thisManySelComps > 1) ) { // everything is controlled by the dialog at this point ... w.show(); } else { alert("Please select at least two comps."); } } } } function buildUI() { if (win != null) { win.basicPnl = win.add('panel', [20,26,480,256], '"Basic":'); win.addHeadRad = win.basicPnl.add('radiobutton', [309,80,445,102], 'add to head'); win.addHeadRad.enabled = false; win.addTailRad = win.basicPnl.add('radiobutton', [309,103,445,125], 'add to tail'); win.addTailRad.value = true; win.addTailRad.enabled = false; win.advPnl = win.add('panel', [20,263,480,398], '"Advanced":'); win.nameSearchLabel = win.add('statictext', [54,48,232,70], 'Search in comp names for:'); win.nameSearchT = win.add('edittext', [65,73,305,95], ''); win.nameDoSearchCheck = win.add('checkbox', [310,73,405,95], 'do search'); win.nameDoSearchCheck.value = true; win.nameDoSearchCheck.onClick = function () { doLinkedEmpty(this, win.nameSearchT); doLinkedEnabled(this, win.nameSearchT); doOppositeEnabled(this, win.addHeadRad); doOppositeEnabled(this, win.addTailRad); }; win.nameReplaceLabel = win.add('statictext', [54,106,260,128], ' ... and replace with (or add):'); win.nameReplaceT = win.add('edittext', [65,131,305,153], ''); // at least in version 6.5, there seems to be a bug in the implementation of 'name' for control objects //(unless i'm missing something); // docs say that every control object can be given a 'name' when '.add'ing, but it seems only buttons can be given names // in this way; everything else (or, at least an edittext object) has to be given a name after '.add'ing win.nameReplaceT.name = "nameReplaceT"; //now this edittext field can be tested for by name, below // well, you see ... i originally had coded this differently; now i don't need the names, but i'm keeping them // here, just in case ... win.widthLabel = win.add('statictext', [41,179,86,201], 'Width:'); win.widthT = win.add('edittext', [89,177,166,199], ''); win.widthT.name = "widthT"; win.heightLabel = win.add('statictext', [41,203,86,225], 'Height:'); win.heightT = win.add('edittext', [89,201,166,223], ''); win.heightT.name = "heightT"; win.reCenterCheck = win.add('checkbox', [41,226,166,248], ' re-center layers'); win.reCenterCheck.value = true; win.reCenterHuhBtn = win.add('button', [170,226,200,246], '?'); win.reCenterHuhBtn.onClick = reCenterHelp; win.frRLabel = win.add('statictext', [187,179,256,201], 'Framerate:'); win.frRT = win.add('edittext', [259,177,329,199], ''); win.frRT.name = "frRT"; win.lenLabel = win.add('statictext', [339,179,384,201], 'Length:'); win.lenT = win.add('edittext', [388,177,464,199], ''); win.lenT.name = "lenT"; win.ratioLabel = win.add('statictext', [268,228,384,250], 'Pixel Aspect Ratio:'); win.ratioT = win.add('edittext', [388,226,428,248], ''); win.ratioT.name = "ratioT"; win.ratioHuhBtn = win.add('button', [438,226,468,246], '?'); win.ratioHuhBtn.onClick = paRatioHelp; win.okBtn = win.add('button', [398,417,478,439], 'OK', {name:'ok'}); win.okBtn.onClick = function () { doMain(this.parent);this.parent.close(1); }; win.cancBtn = win.add('button', [298,417,378,439], 'Cancel', {name:'cancel'}); win.cancBtn.onClick = function () {this.parent.close(0)}; win.helpBtn = win.add('button', [111,417,191,439], 'Help!', {name:'help'}); win.helpBtn.onClick = bigHelp; win.aboutBtn = win.add('button', [21,417,101,439], 'About', {name:'about'}); win.aboutBtn.onClick = doAbout; win.angleLbl = win.add('statictext', [24,287,177,309], 'Shutter Angle (max. 720):'); win.phaseLbl = win.add('statictext', [245,287,425,309], 'Shutter Phase (-360 to 360):'); win.angleT = win.add('edittext', [185,285,225,307], ''); win.angleT.name = "angleT"; win.phaseT = win.add('edittext', [426,285,466,307], ''); win.phaseT.name = "phaseT"; win.doPresFRCheck = win.add('checkbox', [66,342,106,364], 'Do:'); win.doPresFRCheck.value = false; win.presFRCheck = win.add('checkbox', [107,342,437,364], 'Preserve framerate when nested or in render queue'); win.presFRCheck.enabled=false; win.doPresFRCheck.onClick = function () {doLinkedEnabled(this, win.presFRCheck)}; win.doPresRezCheck = win.add('checkbox', [66,366,106,388], 'Do:'); win.doPresRezCheck.value = false; win.presRezCheck = win.add('checkbox', [107,366,437,388], 'Preserve resolution when nested'); win.presRezCheck.enabled = false; win.doPresRezCheck.onClick = function () {doLinkedEnabled(this, win.presRezCheck)}; win.explainEmptiesLbl = win.add('statictext', [10,4,490,22], '(BLANK FIELDS MEAN IGNORE SETTINGS)'); win.explainEmptiesLbl.justify = 'center'; win.explainDoLbl = win.add('statictext', [54,320,446,340], '(An unchecked "Do" checkbox means ignore setting)'); } return win } function paRatioHelp() { alert("The \"known and accurate\" set (please use these number formats):\r" + "1 (Square Pixel)\r.9 (D1/DV NTSC)\r1.2 (D1/DV NTSC Widescreen)\r1.07 (D1/DV PAL)\r" + "1.42 (D1/DV PAL Widescreen)\r2 (Anamorphic 2:1)\r.95 (D4/D16 Sandard)\r1.9 (D4/D16 Anamorphic)"); } function reCenterHelp() { alert("Recentering is meant primarily for 2D layers: you may see unexpected results if you have complex 3D at work in the comps. " + "This operation will UNLOCK all locked layers!\r\r" + "This button is only meaningful if you are changing comp dimensions."); } function makeParentLayerOfAllUnparented(theComp, newParent) { for (var i = 1; i <= theComp.numLayers; i++) { var curLayer = theComp.layer(i); if (curLayer.locked) {curLayer.locked = false;} if (curLayer != newParent && curLayer.parent == null) { curLayer.parent = newParent; } } } function moveParent(pa, axis, amt) { //null is at 000 anyway, so no math needed newPos = [0, 0, 0]; newPos[axis] = amt; pa.position.setValue(newPos); } function doMain(theDialog) { //alert("doing main"); var everyItem = app.project.items; // first we build the comp collection so that renaming doesn't mess up because comps // jump to new positions with new names!! selectedComps = new Array(); for (var i = everyItem.length; i >= 1; i--) { eyeTem = everyItem[i]; if ((eyeTem instanceof CompItem) && eyeTem.selected) { selectedComps[selectedComps.length] = eyeTem; } } app.beginUndoGroup("Change Selected Comps"); for (var n = (selectedComps.length-1); n >= 0; n--) { item = selectedComps[n]; // in order of options: // 1-comp names: // if both are "", ignore, if search empty and replace not, do add to start or end // if both are not empty, do search and replace ////// first name stuff if (theDialog.nameSearchT.text != "") { oldName = item.name; sear = theDialog.nameSearchT.text; repl = theDialog.nameReplaceT.text newName = oldName; //keep renaming until searchstring is no longer in name: while (newName.indexOf(sear) != -1) { newName = (newName.replace(sear, repl)); //names should not be over 31 chars long, so we trim if we need to }//while newName=(newName.substr(0,31)); item.name = newName; } else { if ( (!theDialog.nameDoSearchCheck.value) && (theDialog.nameReplaceT.text != "") ) { oldName = item.name; if (theDialog.addTailRad.value) { newName = (oldName + theDialog.nameReplaceT.text); } else { newName = (theDialog.nameReplaceT.text + oldName); } newName = (newName.substr(0,31)); item.name = newName; } } ///// 2- width ////////////////////////////// now with re-center //////////// // limit=30000 if (theDialog.widthT.text != "") { if (isNaN(parseFloat(theDialog.widthT.text))) { probStr = (probStr + "Not a number value for Width\r"); theDialog.widthT.text = "";//empty field if it is bad so we don't try anymore } else { oldWidth = item.width; newWidth = Math.floor(parseFloat(theDialog.widthT.text)); if ( (newWidth > 30000) || (newWidth < 4) ) { probStr = (probStr + "Value out of range for Width\r"); theDialog.widthT.text = "";//empty field if it is bad so we don't try anymore } else { if (oldWidth != newWidth) { item.width = newWidth; // if 'recenter' checkbox is checked: if (theDialog.reCenterCheck.value) { thisMuch = (-1 * (oldWidth - newWidth)) *.5; null3DLayer = item.layers.addNull(); null3DLayer.threeDLayer = true; doomedNullSrc = null3DLayer.source; null3DLayer.position.setValue([0,0,0]); // Set null3DLayer as parent of all layers that don't have parents. makeParentLayerOfAllUnparented(item, null3DLayer); //null, axis, amt moveParent(null3DLayer, 0, thisMuch); null3DLayer.remove(); doomedNullSrc.remove(); } } } } } ///// 3- height // limit=30000 if (theDialog.heightT.text != "") { if (isNaN(parseFloat(theDialog.heightT.text))) { probStr = (probStr + "Not a number value for Height\r"); theDialog.heightT.text = "";//empty field if it is bad so we don't try anymore } else { oldHeight = item.height; newHeight = Math.floor(parseFloat(theDialog.heightT.text)); if ( (newHeight > 30000) || (newHeight < 4) ) { probStr = (probStr + "Value out of range for Height\r"); theDialog.heightT.text = "";//empty field if it is bad so we don't try anymore } else { if (oldHeight != newHeight) { item.height = newHeight; // if 'recenter' checkbox is checked: if (theDialog.reCenterCheck.value) { thisMuch = (-1 * (oldHeight - newHeight)) *.5; null3DLayer = item.layers.addNull(); null3DLayer.threeDLayer = true; doomedNullSrc = null3DLayer.source; null3DLayer.position.setValue([0,0,0]); // Set null3DLayer as parent of all layers that don't have parents. makeParentLayerOfAllUnparented(item, null3DLayer); //null, axis, amt moveParent(null3DLayer, 1, thisMuch); null3DLayer.remove(); doomedNullSrc.remove(); } } } } } ////////////////////////////////////////// ///// 4- pixel aspect ratio if (theDialog.ratioT.text != "") { if (isNaN(parseFloat(theDialog.ratioT.text))) { probStr = (probStr + "Not a number value for Pixel Aspect Ratio\r"); theDialog.ratioT.text = "";//empty field if it is bad so we don't try anymore } else { item.pixelAspect = parseFloat(theDialog.ratioT.text); } } ///// 5- framerate // limit = 1-99 newFR = item.frameRate; if (theDialog.frRT.text != "") { if (isNaN(parseFloat(theDialog.frRT.text))) { probStr = (probStr + "Not a number value for Framerate\r"); theDialog.frRT.text = "";//empty field if it is bad so we don't try anymore } else { maybeNewFR = parseFloat(theDialog.frRT.text); if ( (maybeNewFR > 99) || (maybeNewFR < 1) ) { probStr = (probStr + "Value out of range for Framerate\r"); theDialog.frRT.text = "";//empty field if it is bad so we don't try anymore } else { newFR = maybeNewFR; item.frameRate = newFR; } } } else { newFR = item.frameRate; } ///// 6- length // limit=323676 if (theDialog.lenT.text != "") { if (isNaN(parseFloat(theDialog.lenT.text))) { probStr = (probStr + "Not a number value for Length\r"); theDialog.lenT.text = "";//empty field if it is bad so we don't try anymore } else { newDur = parseFloat(theDialog.lenT.text); durCalc = newDur/newFR; if ( (durCalc > 323676) || (durCalc < 1) ) { probStr = (probStr + "Value out of range for Length\r"); theDialog.frRT.text = "";//empty field if it is bad so we don't try anymore } else { item.duration = durCalc; } } } ///// 7- shutter angle if (theDialog.angleT.text != "") { if (isNaN(parseFloat(theDialog.angleT.text))) { probStr = (probStr + "Not a number value for Shutter Angle\r"); theDialog.angleT.text = "";//empty field if it is bad so we don't try anymore } else { newValue = parseFloat(theDialog.angleT.text); if (newValue > 720) { probStr = (probStr + "Number given for Shutter Angle too high\r"); theDialog.angleT.text = "";//empty field if it is bad so we don't try anymore } else if (newValue < 0) { probStr = (probStr + "Number given for Shutter Angle too low\r"); theDialog.angleT.text = "";//empty field if it is bad so we don't try anymore } else { item.shutterAngle = newValue; } } } ///// 8- shutter phase if (theDialog.phaseT.text != "") { if (isNaN(parseFloat(theDialog.phaseT.text))) { probStr = (probStr + "Not a number value for Shutter Phase\r"); theDialog.phaseT.text = "";//empty field if it is bad so we don't try anymore } else { newValue = parseFloat(theDialog.phaseT.text); if (newValue < -360) { probStr = (probStr + "Number given for Shutter Phase too low\r"); theDialog.phaseT.text = "";//empty field if it is bad so we don't try anymore } else if (newValue > 360) { probStr = (probStr + "Number given for Shutter Phase too high\r"); theDialog.phaseT.text = "";//empty field if it is bad so we don't try anymore } else { item.shutterPhase = newValue; } } } ///// 9- preserve fr if (theDialog.doPresFRCheck.value) { item.preserveNestedFrameRate = (theDialog.presFRCheck.value); } ///// 10- preserve rez if (theDialog.doPresRezCheck.value) { item.preserveNestedResolution = (theDialog.presRezCheck.value); } } app.endUndoGroup(); if (probStr != "") {alert("The following problems were found (these settings were not changed!):\r" + probStr);} } function doLinkedEmpty(clickedThing, target) { if (clickedThing.value == false) { target.text = ""; } } function doLinkedEnabled(clickedThing, target) { target.enabled = clickedThing.value; } function doOppositeEnabled(clickedThing, target) { target.enabled = !clickedThing.value; }