//Compify //Byron Nash, Edited and Improved by Paul Tuersley //October 2004 // //Select footage items to be comped or select none to comp all //enter a suffix at prompt to be appended to the end of the comp name { //opening brace var suffixText = "Untitled"; var frameRate = 10 var dur = 1 function createDialog(){//function to create the dialog function onTimeCodeClick(){//enables timecode fields timeCodeRb.value = true; frRb.value = false; frEt.enabled = false; tcHEt.enabled = true; tcMEt.enabled = true; tcSEt.enabled = true; tcFEt.enabled = true; dlg.stillPnl.rateEt.active = false; frEt.active = false; tcSEt.active = true; } function onFrameClick(){//enables frames field timeCodeRb.value = false; frRb.value = true; frEt.enabled = true; tcHEt.enabled = false; tcMEt.enabled = false; tcSEt.enabled = false; tcFEt.enabled = false; tcSEt.active = false; dlg.stillPnl.rateEt.active = false; frEt.active = true; } // added a custom click function so the edittxt box gets highlighted. function onCustomClick() { frEt.active = false; tcSEt.active = false; dlg.stillPnl.rateEt.active = true; } //Setup Button bounds and placement // Horizontal Spacing variables var left_margin_width = 5; var right_margin_width = 5; var between_button_width = 8; // Width of buttons var button_width = 90; var button_height = 12; var button_extra = 3; //Variables to describe the button size and placement var button_left = left_margin_width; var button_right = button_left + button_width; var button_top = 20; var button_bottom = button_top + button_height; var palette_width = button_right + right_margin_width; // Create dialog window var dlg = new Window('dialog', 'Compify', [300,300,500,545]); //main panel dlg.stillPnl = dlg.add('panel', [5,28,195,208], 'Settings for still images'); //field for entering a suffix to the comp dlg.sufSt = dlg.add('statictext', [8,5,45,25], 'Suffix'); var suffixEt = dlg.add('edittext', [55,5,195,25], '' ) ; //add radio buttons for the different frame rates //increment the button placement in between creation of buttons dlg.stillPnl.NTSC = dlg.stillPnl.add('radiobutton',[button_left,button_top,button_right+50,button_bottom],'29.97 [NTSC]'); dlg.stillPnl.NTSC.value = true;//initialize the value button_top = button_top + button_height + between_button_width; button_bottom = button_top + button_height; dlg.stillPnl.PAL = dlg.stillPnl.add('radiobutton',[button_left,button_top,button_right,button_bottom],'25 [PAL]'); button_top = button_top + button_height + between_button_width; button_bottom = button_top + button_height; dlg.stillPnl.film = dlg.stillPnl.add('radiobutton',[button_left,button_top,button_right,button_bottom],'24'); button_top = button_top + button_height + between_button_width; button_bottom = button_top + button_height; dlg.stillPnl.custom = dlg.stillPnl.add('radiobutton',[button_left,button_top,button_right,button_bottom],'Custom'); dlg.stillPnl.rateEt = dlg.stillPnl.add('edittext', [button_right,button_top-4,button_right+40,button_bottom+4], '30'); button_top = button_top + button_height + between_button_width; button_bottom = button_top + button_height; //add a panel for the duration, reset the button placement //increment in between dlg.stillPnl.durPnl = dlg.stillPnl.add('panel',[0,button_top,190,180],''); button_top = 6; button_bottom = button_top + button_height + between_button_width; var durSt = dlg.stillPnl.durPnl.add('statictext', [button_left,button_top,button_right,button_bottom], 'Comp Duration'); button_top = button_top + button_height + 12; button_bottom = button_top + button_height; //frames radio and text box var frRb = dlg.stillPnl.durPnl.add('radiobutton',[button_left,button_top,button_right,button_bottom],'Frames'); var frEt = dlg.stillPnl.durPnl.add('edittext', [button_right,button_top-4,button_right+35,button_bottom+4], '150'); button_top = button_top + button_height + between_button_width+2; button_bottom = button_top + button_height+2; //timecode radio and fields for entering in timecode var timeCodeRb = dlg.stillPnl.durPnl.add('radiobutton',[button_left,button_top,button_right,button_bottom],'Timecode'); var timecodeWidth = 21; var timecodeSpace = 2; var tcHEt = dlg.stillPnl.durPnl.add('edittext', [button_right,button_top-4,button_right+timecodeWidth,button_bottom+4], '00'); button_right = button_right + timecodeWidth + timecodeSpace; var tcMEt = dlg.stillPnl.durPnl.add('edittext', [button_right,button_top-4,button_right+timecodeWidth,button_bottom+4], '00'); button_right = button_right + timecodeWidth + timecodeSpace; var tcSEt = dlg.stillPnl.durPnl.add('edittext', [button_right,button_top-4,button_right+timecodeWidth,button_bottom+4], '10'); button_right = button_right + timecodeWidth + timecodeSpace; var tcFEt = dlg.stillPnl.durPnl.add('edittext', [button_right,button_top-4,button_right+timecodeWidth,button_bottom+4], '00'); //initialize the values timeCodeRb.value = true; frRb.value = false; frEt.enabled = false; tcHEt.enabled = true; tcMEt.enabled = true; tcSEt.enabled = true; tcFEt.enabled = true; //buttons for ok and cancel var OKBtn = dlg.add('button', [138,215,193,235],'OK', {name:'ok'}); var cancelBtn = dlg.add('button', [77,215,132,235],'Cancel', {name:'cancel'}); //send clicks to functions for enabling/disabling buttons timeCodeRb.onClick = onTimeCodeClick; frRb.onClick = onFrameClick; dlg.stillPnl.custom.onClick = onCustomClick; if(dlg.show() == 1){ suffixText = suffixEt.text; //alert(suffixText);//debugging //Figure out what frame rate is checked if(dlg.stillPnl.NTSC.value == true){ frameRate = 29.97;//NTSC } else if(dlg.stillPnl.PAL.value == true) { frameRate = 25;//PAL } else if(dlg.stillPnl.film.value == true) { frameRate = 24;//Film } else if(dlg.stillPnl.custom.value == true) { frameRate = dlg.stillPnl.rateEt.text;//get value from text box } //set comp length for still images if(frRb.value == true){ dur = frEt.text/30;//take the frames value //alert('using frEt ' + frEt.text); //debugging } else { var h = Number(tcHEt.text * 3600);//multiply hours var m = Number(tcMEt.text * 60);//multiply minutes var s = Number(tcSEt.text);//multiply seconds var f = Number(tcFEt.text/30);//divide frames dur = h+m+s+f;//add'em up //alert('using TC ' + dur+ ' f is:'+ tcFEt.text); //debugging } //setup array to return tempInfo = [suffixText,frameRate,dur] return tempInfo } } clearOutput(); var proj = app.project;//set project //call the dialog function var stillInfo = createDialog(); //NOTE!!!! // by testing if anything was returned by the createDialog function, you know whether // the user ok'ed or cancelled. This main body of the script will only execute if something // was returned (i.e if stillInfo isn't null); if (stillInfo) { // create undo group if user didn't cancel dialog app.beginUndoGroup("Compify"); var projColl = proj.items;//list of items in project writeLn("======Compify=======Byron Nash======"); var myComps = new Array();//array for storing all the comps made var selItems = app.project.selection;//set selected import items to an array if (selItems.length > 0){//check to see if anything is selected var myColl = app.project.selection;//if so the use the selection var i = 0; } else {//if not, use entire project contents var myColl = new Array(); for (j=0; j < projColl.length; j++){//add project list to an array myColl[j] = projColl[j+1]; } } var suffix = stillInfo[0];//get suffix from array for (i=0; i <= myColl.length; i++) {//loop through the project var curItem = myColl[i]; if (curItem instanceof FootageItem) {//check for footage items var extPos = curItem.name.lastIndexOf(".");//find file extension //add suffux to comp name and remove the file extension var curName = curItem.name.substring(0, extPos) + " " + suffix; //Truncate comp name if it exceeds the 31 character limit if (curName.length > 30){ curName = curName.slice(0,29-suffix.length) + " " + suffix; } //setup comp variables var curWidth = curItem.width; var curHeight = curItem.height; var curAspect = curItem.pixelAspect; var curDuration = curItem.duration; var curRate = curItem.frameRate; if (curDuration == 0){ curDuration = stillInfo[2] //set duration to dialog value if it is a still image } if (curRate < 1){ curRate = stillInfo[1]//set frame rate to dialog value if it is a still image } //create comp and add layer var newComp = projColl.addComp(curName,curWidth,curHeight,curAspect,curDuration,curRate);//make new comp var lcoll = newComp.layers;//variable for collection of layer objects in logoComp lcoll.add(curItem);//add layer myComps[myComps.length] = newComp;//add comp to array } } writeLn("Created " + myComps.length + " Comps"); app.endUndoGroup(); } }//closing