Answered
Set Work Area Start and end according to selected layers. issue with the position of the work area.
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();