Skip to main content
johnt53984649
Inspiring
September 11, 2016
Question

Script to Change Active Composition Duration

  • September 11, 2016
  • 2 replies
  • 1431 views

This should be really simple, but I can't seem to get it right.  I need a script that takes the active composition and changes duration to be EXACTLY 4 seconds long.  I'm using a 59.94 fps timecode that is non-drop frame.  So whenever this script is run, the only thing it should do is change the active composition so that it starts at 0:00:00:00 (hours, minutes, seconds, frames) and ends at 0:03:59:59.  I tried to use the "duration" in my script, but when I set it equal to 240 (60 seconds * 4), my composition ended up at 0:03:59:45 for some reason.  My frames were messed up.  Can somebody please show me a script that allows will do exactly what I have in bold above?

This topic has been closed for replies.

2 replies

johnt53984649
Inspiring
October 2, 2016

This is really helpful, but let's say I don't want there to be any prompt and I just automatically want it to set the duration to four seconds.  How would I do this with no prompt?

UQg
Legend
October 2, 2016

myComp.duration = currentFormatToTime("00:00:04:00", myComp.frameRate);

or simply:

myComp.duration = 4;

phlexib
Inspiring
September 12, 2016

Try this, it works for me. you can select multiple comps and change them all :

{

    app.beginUndoGroup("Change Comp Duration");

var newStartTime = prompt ("enter new starTime in Timecode format", "NEW StarTime");

var newDuration = prompt ("enter new duration in Frames:", "NEW DURATION");

var listElements = app.project.selection;

for (var i=0; i< listElements.length; i++){

    if(listElements instanceof CompItem){

    listElements.displayStartTime = timecodeToTime(newStartTime,listElements);

    var fR = listElements.frameRate;

    var secDuration = newDuration/fR;

    listElements.duration =secDuration;

  }

}

app.endUndoGroup();

alert ("new Comp Duration set to " + newDuration +" frames");

function timecodeToTime(starTime,comp){

  var seconds = currentFormatToTime(starTime,comp.frameRate);

  return seconds;

}

}

Ben