Copy link to clipboard
Copied
I have a scrip that sets work area start and end according to the selected layer(s), but it doest position the work area correctly if the comp duration is large.
// After Effects script to set work area to selected layers' start and end points
app.beginUndoGroup("Set Work Area to Selected Layers");
var comp = app.project.activeItem; // Get the active composition
if (comp && comp instanceof CompItem) { // Ensure that there is an active composition
var selectedLayers = comp.selectedLayers; // Get selected layers
if (selectedLayers.length > 0) {
var workAreaStart = selectedLayers[0].inPoint;
var workAreaEnd = selectedLayers[0].outPoint;
// Loop through the selected layers to find the earliest start and latest end points
for (var i = 0; i < selectedLayers.length; i++) {
var layer = selectedLayers[i];
if (layer.inPoint < workAreaStart) {
workAreaStart = layer.inPoint;
}
if (layer.outPoint > workAreaEnd) {
workAreaEnd = layer.outPoint;
}
}
// Set the work area start and duration
comp.workAreaStart = workAreaStart;
comp.workAreaDuration = workAreaEnd - workAreaStart;
} else {
}
} else {}
app.endUndoGroup();
Apparently, there are some restrictions (bug?) on how you can set the work area start and duration based on the currents settings. Replacing these two lines:
comp.workAreaStart = workAreaStart;
comp.workAreaDuration = workAreaEnd - workAreaStart;
with these:
comp.workAreaStart = 0;
comp.workAreaDuration = comp.duration;
comp.workAreaStart = workAreaStart;
comp.workAreaDuration = workAreaEnd - workAreaStart;
seems to work in all the situations I could think of.
Copy link to clipboard
Copied
How large of a comp duration causes the script to malfunction?
Copy link to clipboard
Copied
Sorry I didn't write it properly,
so whenever the selected layers are before the work area end in the timeline, it works completely fine but if the layers are after it the script doesnt work properly it creates the work area of the same duration but fails to position the work area according to selected layer, snd sometimes just doesnt work in larger comps.
I tried it on a 3hr comp, just to test it, and found out that the smaller the size of the layer after the "work are end" is the worse it gets.
I made a script that sets the work area start to the playhead, and had the same issue, and I think its the work area start thats causing the problem here aswell , because I made a "set work area end to playhead" as well and it was way easier.
Copy link to clipboard
Copied
Apparently, there are some restrictions (bug?) on how you can set the work area start and duration based on the currents settings. Replacing these two lines:
comp.workAreaStart = workAreaStart;
comp.workAreaDuration = workAreaEnd - workAreaStart;
with these:
comp.workAreaStart = 0;
comp.workAreaDuration = comp.duration;
comp.workAreaStart = workAreaStart;
comp.workAreaDuration = workAreaEnd - workAreaStart;
seems to work in all the situations I could think of.
Copy link to clipboard
Copied
This works Flawlessly, thank you, Dan. You're a God amongst men.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now