You need to loop through each of the selected project items. This should do it:
// prompt the user for input
var Start = prompt ("Enter start time (in frames)",0);
var Length = prompt ("How long should the work area be?", 1);
// set an undo group so the user can revert the change if they make a mistake
app.beginUndoGroup("Change work area in selected comps");
// let's keep track of how many comps we modify, so we can report back at the end
var modifiedCompCounter = 0;
// step through each selected item in the project panel
for (var i = 0; i < app.project.selection.length; i++) {
// we only want to work on comps
if (app.project.selection[i] instanceof CompItem) {
var myComp = app.project.selection[i];
myComp.workAreaStart = Start/myComp.frameRate;
myComp.workAreaDuration = Length/myComp.frameRate;
myComp.time = myComp.workAreaDuration + myComp.workAreaStart; // note the "+ myComp.workAreaStart" here -- without this, the script only sets the correct CTI position if the work area begins at 0
modifiedCompCounter++; // increase our changed comp counter
}
}
// write the number of comps we changed to the Info panel
writeLn("Modified work area in " + modifiedCompCounter + " comp(s).");
// close the undo group
app.endUndoGroup();
I’ve added a few good practices: some comments so it’s easy to tell what’s going on, a check to make sure we only try to modify comps, an Undo group so the user can change their minds after they use the script, and a little Info panel notification about the change.
Please do ask questions on anything that isn’t clear. I’d be happy to help.
Walter Soyka
Designer & Mad Scientist at Keen Live [link]
Motion Graphics, Widescreen Events, Presentation Design, and Consulting
@keenlive | RenderBreak [blog] | Profile [LinkedIn]