Skip to main content
Inspiring
January 19, 2019
Question

workAreaStart and workAreaDuration behaviour in ExtendScript

  • January 19, 2019
  • 3 replies
  • 1215 views

Dear forum,

I try to copy the workAreaStart and workAreaDuration from one comp to another, but I don't understand the results. There are two identical comps in a project. Manually I set the start and duration in one comp and by script I want it to be applied to the other. But when I change the workarea (start and duration) of the first comp, run the script and repeat all this a few times, the second comp's workarea is quite different then the source. The debug output is giving the right frames, it's just somehow applied different to the destination.

Why and How? Can somebody explain me what is going on? Many thanks!

The script needs only 2 comps.

var sourceComp = app.project.item(1);

var destComp = app.project.item(2);

var frameStart = Math.round(sourceComp.workAreaStart * sourceComp.frameRate);

var frameDuration = Math.round(sourceComp.workAreaDuration * sourceComp.frameRate);

// alert(frameStart+”, “+frameDuration);

destComp.workAreaStart = frameStart/sourceComp.frameRate;

destComp.workAreaDuration = frameDuration/sourceComp.frameRate;

destComp.openInViewer();

This topic has been closed for replies.

3 replies

Participating Frequently
July 26, 2022

I found a workaround.

 

In order to get this to work, you need to create a for loop separatedly where you go through all the CompItems and define the workAreaStart and Duration inside each pre comp.

 

Make sure that your times are Timecode (0:00:00:21) and you use currentFormatToTime when setting the times for workAreaStart and Duration.

 

 

   for (t = 1; t <= app.project.items.length; t++) {
        if (app.project.items[t] instanceof CompItem) {
           
            if (app.project.items[t].name != "main") {
                compSelected = app.project.item(t);
               
                var timesToSelect = String(compSelected.markerProperty.keyValue(1).comment);
                var timesForSelection = timesToSelect.split("-");
           
                timeStart =currentFormatToTime(timesForSelection[0],currentComp.frameRate);
                compSelected.workAreaStart = timeStart; //in seconds
                calcWorkAreaDuration =  currentFormatToTime(timesForSelection[1],currentComp.frameRate)- currentFormatToTime(timesForSelection[0],currentComp.frameRate);
                alert(calcWorkAreaDuration);
                compSelected.workAreaDuration = calcWorkAreaDuration; //in seconds
            }
        }
    }

 

           
Community Expert
July 8, 2022

can confirm similar behavior in the latest AE - it takes several runs to set the correct workareastart and duration.

Participating Frequently
July 26, 2022

Same here, I'm trying to run a loop where I define the workAreaStart and Duration across several comps and it breaks on the first loop after setting the first comp.

Inspiring
January 20, 2019

I tried a little more but still don’t understand what is going on.

Sometimes Comp2 gets the identical workareaStart, other times the script needs to run a few times to get to the right start position.

For this test you need a new project with 2 new empty comps.

var sourceComp = app.project.item(1);

var destComp = app.project.item(2);

destComp.workAreaStart = sourceComp.workAreaStart;

destComp.workAreaDuration = sourceComp.workAreaDuration;