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

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

New Here ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

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();

 

TOPICS
Expressions , Scripting

Views

425

Translate

Translate

Report

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
New Here ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

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 

Phoenix33861833yqyj_0-1723916917585.png

 

Votes

Translate

Translate

Report

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 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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
New Here ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

It seems to work for me, but I may not be testing it in the same way.

 

<edit>

Also, I put those lines at line 30.

Votes

Translate

Translate

Report

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 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

Actually, just ignore everything I suggested. You code works fine for me, but I must not be testing the way you are.

Votes

Translate

Translate

Report

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
New Here ,
Aug 18, 2024 Aug 18, 2024

Copy link to clipboard

Copied

It works with a different approach.

            var oneFrame = 1 / comp.frameRate;

            comp.workAreaStart = 0;
            comp.workAreaDuration = comp.duration;            
            comp.workAreaStart = playheadPosition;
            comp.workAreaDuration = currentWorkAreaEnd - playheadPosition + oneFrame;
            comp.workAreaDuration = comp.workAreaDuration - oneFrame;

Votes

Translate

Translate

Report

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
New Here ,
Aug 18, 2024 Aug 18, 2024

Copy link to clipboard

Copied

LATEST

also the issues happens when my frame rate is, 23.976, its just unable to set the work area duration correctly, but with 24 frames it works properly

Votes

Translate

Translate

Report

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
New Here ,
Aug 17, 2024 Aug 17, 2024

Copy link to clipboard

Copied

I'll try that.

 

Votes

Translate

Translate

Report

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