Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions change precomp length for all precomps

  • change precomp length for all precomps

    Posted by Josh Weiss on January 16, 2008 at 8:31 pm

    Ok, so my question is regarding a script, and not an expression. The script is very useful and I used to use it all the time in AE7. The script allows you to change the length of all precomps and solids within precomps. So, for instance if you have a comp with 3 precomps and want to change from 30 frames to 60 you just use this script and it changes all 3 precomps, the main comp, and all layers in the precomps.

    However, in AE8 (mac or PC) it no longer works. Any ideas?

    //Byron Nash, edited and improved by Paul Tuersley
    //Nov. 2004
    //Set all precomps and comps in to main comp’s duration
    //Select a comp or have it as the active item
    //Script will change the length and out point of all comps and stills to the length of the current comp

    {//open
    app.beginUndoGroup(“Retime all precomps”);

    var dur = Number(7);//setup duration variable

    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;
    writeLn(“You Clicked TC, it is now: ” + tcHEt.text+tcMEt.text+tcSEt.text+tcFEt.text);
    }

    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;
    writeLn(“You Clicked Frames, it is now: ” + frEt.text);
    }

    function onFrameChange(){//when a user changes the number
    var framedur = Number(frEt.text/30);//take the frames value
    writeLn(“frames changed to: ” + framedur);
    return framedur;
    }

    function onTimeCodeChange(){//when a user changes the number
    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
    var tcdur = Number(h+m+s+f);//add’em up
    writeLn(“Timecode changed to: ” + tcdur);
    return tcdur;
    }

    function onOKClick(){//set variables
    //set comp length for still images
    if(frRb.value == true){
    dur = onFrameChange();
    //alert(‘using frEt ‘ + dur); //debugging
    }else{
    dur = onTimeCodeChange();
    //alert(‘using TC ‘ + dur ); //debugging
    }
    writeLn(‘New Duration is: ‘ + dur);
    }

    // changeCompDuration function
    // change comp duration
    // check each layer in comp
    // if layer is a precomp, recursive function, then change its outpoint
    // else if still footage, change its outpoint

    function changeCompDuration(myComp){
    //alert(‘entering changeComp function – setting ‘ + myComp.name + ” duration”);
    myComp.duration = compDur;
    var lcoll = myComp.layers;//collection of layer objects in Comp

    for (var i=1; i<=lcoll.length; ++i){ //loop through each layer in the comp var selItem = lcoll[i]; var skip = false; if (selItem.property("intensity") != null){ skip = true; // Layer is a light layer selItem.outPoint = compDur; } if (selItem.property("zoom") != null){ // Layer is a camera layer } skip = true; selItem.outPoint = compDur; } if (skip == false){ var selItem = lcoll[i].source; //find layer source in project //alert("checking " + lcoll[i].name); if(selItem instanceof CompItem) {//check for comp changeCompDuration(selItem); lcoll[i].outPoint = compDur;//set layer out point to comp out point } else { //alert("Is it a still? " + lcoll[i].source.duration); //duration will be 0 on still footage //alert("setting still's outpoint"); if (lcoll[i].source.duration == 0) { lcoll[i].outPoint = compDur;//set layer out point to comp out point } } } } return }//close comp function clearOutput(); var myComp = app.project.activeItem; if(myComp instanceof CompItem) { // Create the dialog //Setup Button bounds and placement // Horizontal Spacing variables var left_margin_width = 5; var right_margin_width = 5; var between_button_width = 5; // Width of buttons var button_width = 80; var button_height = 15; //Variables to describe the button size and placement var button_left = left_margin_width; var button_right = button_left + button_width; var button_top = 19; var button_bottom = button_top + button_height; var palette_width = button_right + right_margin_width; var dlg = new Window('dialog', 'Re-Lengthify', [400,400,600,500]); //main panel dlg.stillPnl = dlg.add('panel', [5,4,195,66], 'New Comp Length'); //frames radio and text box var frRb = dlg.stillPnl.add('radiobutton',[button_left,button_top,button_right,button_bottom],'Frames'); var frEt = dlg.stillPnl.add('edittext', [button_right,button_top-5,button_right+35,button_bottom], '77'); 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.add('radiobutton',[button_left,button_top,button_right,button_bottom],'Timecode'); var timecodeWidth = 23.5; var timecodeSpace = 2; var tcHEt = dlg.stillPnl.add('edittext', [button_right,button_top-5,button_right+timecodeWidth,button_bottom], '00'); tcHEt.justify = "center"; button_right = button_right + timecodeWidth + timecodeSpace; var tcMEt = dlg.stillPnl.add('edittext', [button_right,button_top-5,button_right+timecodeWidth,button_bottom], '00'); tcMEt.justify = "center"; button_right = button_right + timecodeWidth + timecodeSpace; var tcSEt = dlg.stillPnl.add('edittext', [button_right,button_top-5,button_right+timecodeWidth,button_bottom], '10'); tcSEt.justify = "center"; button_right = button_right + timecodeWidth + timecodeSpace; var tcFEt = dlg.stillPnl.add('edittext', [button_right,button_top-5,button_right+timecodeWidth,button_bottom], '00'); tcFEt.justify = "center"; //buttons for ok and cancel dlg.btnPnl = dlg.add('panel',[91,68,195,95],''); var OKBtn = dlg.btnPnl.add('button', [3,3,50,23],'OK', {name:'ok'}); var cancelBtn = dlg.btnPnl.add('button', [54,3,101,23],'Cancel', {name:'cancel'}); //send clicks to functions for enabling/disabling buttons timeCodeRb.onClick = onTimeCodeClick; frRb.onClick = onFrameClick; frEt.onChange = onFrameChange; tcHEt.onChange = onTimeCodeChange; tcMEt.onChange = onTimeCodeChange; tcSEt.onChange = onTimeCodeChange; tcFEt.onChange = onTimeCodeChange; OKBtn.onClick = onOKClick; //done creating dialog if(dlg.show() == 1){//If the dialog is closed with OK, set the dur variable if(frRb.value == true){//test to see what button is checked dur = onFrameChange(); //alert('using frEt ' + dur); //debugging }else{ dur = onTimeCodeChange(); //alert('using TC ' + dur ); //debugging } var compDur = dur;//set variable from dur value; changeCompDuration(myComp); }else{ writeLn('Canceled'); } }else{ alert ("Please select a comp and run again.\n" + " Thank You.\n" ); } app.endUndoGroup; }//close

    Vince Quattro replied 13 years, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Vince Quattro

    October 6, 2012 at 7:02 pm

    your for() loop was missing some attributes:

    for (var i=1; i; i++){
    var selItem = lcoll[i];

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy