Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Add marker everytime a value is detected

  • Add marker everytime a value is detected

  • Rodrigo Aben

    April 27, 2020 at 2:18 am

    I wrote the code below to detect whether opacity value meets a certain threshold and add a marker, except it stops at the first time it finds the value.

    I want it to continue finding matches and add multiple markers until it reaches frame 100.

    What am I missing?

    Thanks!

    var comp = app.project.activeItem;
    var videoLayer = comp.selectedLayers[0];
    var time = comp.time;
    var frame = Math.round(time/comp.frameDuration);
    var opacityLevel = videoLayer.property("Transform").property("Opacity");
    var threshold = 48.0;

    above = false;
    while (true){
    t = frame * comp.frameDuration;
    if (above){
    if (opacityLevel.valueAtTime(t,true) != threshold){
    frame++;
    }
    }else if (opacityLevel.valueAtTime(t,true) == threshold){
    above = true;
    var myMarker = new MarkerValue("Cut");
    videoLayer.property("Marker").setValueAtTime(t, myMarker);
    }
    if (frame == 100){
    break;
    }
    frame++;
    }

  • Andrei Popa

    April 27, 2020 at 7:00 am

    First of all, never do a while loop with a condition that is always true. You should put your break condition there.

    And your above variable does not let the script check again for threshold equality. You must have a situation when that gets back to false.

    Haven’t tested, but give this a try:


    var comp = app.project.activeItem;
    var videoLayer = comp.selectedLayers[0];
    var time = comp.time;
    var frame = Math.round(time / comp.frameDuration);
    var opacityLevel = videoLayer.property("Transform").property("Opacity");
    var threshold = 48.0;

    above = false;
    while (frame <= 100) {
    t = frame * comp.frameDuration;
    if (above) {
    if (opacityLevel.valueAtTime(t, true) != threshold) {
    frame++;
    above = false;
    }
    } else if (opacityLevel.valueAtTime(t, true) == threshold) {
    above = true;
    var myMarker = new MarkerValue("Cut");
    videoLayer.property("Marker").setValueAtTime(t, myMarker);
    }
    frame++;
    }

    Andrei
    My Envato portfolio.

  • Rodrigo Aben

    April 27, 2020 at 5:59 pm

    Works like a charm! Thanks Andrei!

Viewing 1 - 3 of 3 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy