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

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

Community Beginner ,
Aug 17, 2024 Aug 17, 2024

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
845
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

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

 

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

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

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

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.

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

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

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

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

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

I'll try that.

 

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