Skip to main content
Participating Frequently
August 17, 2024
Question

Work Area start doesn't set when the playhead is one frame before work area end.

  • August 17, 2024
  • 1 reply
  • 928 views

I have a script that sets work area start to playhead, but if doesnt set work area start to playhead when playhead it one frame before work area end.

Thank you 🙏

app.beginUndoGroup("Set Work Area to selected layers");
{
    // Get the current active composition
    var comp = app.project.activeItem;

    if (comp instanceof CompItem) {
        // Save the current work area start and end
        var currentWorkAreaStart = comp.workAreaStart;
        var currentWorkAreaEnd = comp.workAreaStart + comp.workAreaDuration;

        // Set the work area start and end to the composition start and full duration
        comp.workAreaStart = 0;
        comp.workAreaDuration = comp.duration;

        // Get the current playhead time (time indicator)
        var playheadPosition = comp.time;

        if (playheadPosition >= currentWorkAreaEnd) {
            // If the playhead is after or at the current work area end
            var newWorkAreaStart = playheadPosition;
            var workAreaLength = currentWorkAreaEnd - currentWorkAreaStart;

            // Set the new work area start to the playhead position
            comp.workAreaStart = newWorkAreaStart;

            // Set the work area end based on the previous work area length
            comp.workAreaDuration = workAreaLength;
        } else {
            // Otherwise, set the work area start to the playhead position and the end to the previous work area end
            
            comp.workAreaStart = playheadPosition;
            comp.workAreaDuration = currentWorkAreaEnd - playheadPosition;
        }
    } else {
        
    }
}

app.endUndoGroup();

 

This topic has been closed for replies.

1 reply

Participating Frequently
August 17, 2024

I have a script that sets work area start to playhead, but it doesn't set work area start to playhead when playhead is one frame before work area end.
(there are some mistakes in the main post, and i don't know if you can edit the posts)
Thank you 

 

Dan Ebberts
Community Expert
Community Expert
August 17, 2024

I thik it's the same issue as your previous post. Try replacing this:

comp.workAreaStart = playheadPosition;
comp.workAreaDuration = currentWorkAreaEnd - playheadPosition;

with this:

comp.workAreaStart = 0;
comp.workAreaDuration = comp.duration;
comp.workAreaStart = playheadPosition;
comp.workAreaDuration = currentWorkAreaEnd - playheadPosition;
Participating Frequently
August 17, 2024

I did set that at line 12 and 13, but it just doesn't work for some reason.