FORUMS: list search recent posts

[scripting] How to improve this script and also make it affect ALL selected comps?

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Saxon Rix
[scripting] How to improve this script and also make it affect ALL selected comps?
on Oct 11, 2019 at 8:13:57 pm

Hi all,

I needed a script that would batch set the work area start & end points as well as move the Current Time Indicator to the end of the work area end point. This is my very first time scripting, but after a couple of hours digging around I managed to get this working:

var myComp = app.project.activeItem;
var Start = prompt ("Enter start time (in frames)",0);
var Length = prompt ("How long should the work area be?",1);
myComp.workAreaStart = Start/myComp.frameRate;
myComp.workAreaDuration = Length/myComp.frameRate;
myComp.time = myComp.workAreaDuration;


However, I'm wanting it to work on all compositions I have selected in the project panel, not just one (which it currently does). Could someone help me out on how to get that to happen?


Return to posts index

Walter Soyka
Re: [scripting] How to improve this script and also make it affect ALL selected comps?
on Oct 11, 2019 at 9:23:09 pm

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 [twitter]   |   RenderBreak [blog]   |   Profile [LinkedIn]


Return to posts index

Saxon Rix
Re: [scripting] How to improve this script and also make it affect ALL selected comps?
on Oct 12, 2019 at 10:46:22 am

Wow that's great, thanks so much!

I've literally only just started learning scripting yesterday, so this is great for me to dissect and learn further!

The comments really help to break up the script, so I'll definitely follow that structure in the future.

I think I'm making sense of what each bit does, the difficult part is understanding what elements you can and can't use (though I have been following this http://expressions.aenhancers.com/ to help with that), as well well as what some other elements such as '[i]' do etc.

I picked up this course to go through: https://www.provideocoalition.com/after-effects-extendscript-training-compl...

But was wondering if you might be able to recommend any others that are easy to follow too?


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2019 CreativeCOW.net All Rights Reserved
[TOP]