Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Set Work Area Start and end according to selected layers. issue with the position of the work area.

Community Beginner ,
Aug 16, 2024 Aug 16, 2024

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();
TOPICS
Expressions , Scripting
633
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 16, 2024 Aug 16, 2024

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.

Translate
Community Expert ,
Aug 16, 2024 Aug 16, 2024

How large of a comp duration causes the script to malfunction?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2024 Aug 16, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2024 Aug 16, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2024 Aug 17, 2024
LATEST

This works Flawlessly, thank you, Dan. You're a God amongst men.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines