Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Triggering clips based on a black and white map

  • Triggering clips based on a black and white map

    Posted by Sean Mcclintock on April 25, 2013 at 8:12 pm

    Have a grid of clips that I’d like to trigger based on a black and white map. I’m able to reference the map and see when the clips need to be triggered but not sure what comes next. Will eventually be a grid of something like 10×6 clips if that matters. Would I need to continually loop back through the comp so see when the reference map changes from white to black?

    targetLayer =thisComp.layer("Controls").effect("B&W Map")("Layer")
    samplePoint =thisComp.layer("tt_footage_2").transform.position
    sampleRadius = [1,1];
    sampledColor_8bpc = 255 * targetLayer.sampleImage(samplePoint, sampleRadius);
    R = Math.round(sampledColor_8bpc[0]);

    if(R > 0){
    outputString = "OFF";
    frame = 0
    }else{
    outputString = "ON";
    frame = time
    }

    Sean Mcclintock replied 13 years, 4 months ago 2 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    April 25, 2013 at 8:20 pm

    >Would I need to continually loop back through the comp so see when the reference map changes from white to black?

    Yes. You can manipulate the time parameter of sampleImage() to go back in time. That should give how long it has been since the most recent change from white to black.

    Dan

  • Sean Mcclintock

    April 25, 2013 at 8:40 pm

    Thanks Dan. Really appreciate you taking the time to help out people like myself.

  • Sean Mcclintock

    April 25, 2013 at 8:52 pm

    Here’s what I have but it I think I must be missing something.

    targetLayer =thisComp.layer("Controls").effect("B&W Map")("Layer")
    samplePoint =thisComp.layer("tt_footage_2").transform.position
    sampleRadius = [1,1];

    for (f = timeToFrames(inPoint);
    f<= timeToFrames(); f++){
    t = framesToTime(f);
    sampledColor_8bpc = 255 * targetLayer.sampleImage(samplePoint, sampleRadius,true,t);
    R = Math.round(sampledColor_8bpc[0]);

    if (R>1 ){ above = true; break;
    }
    }

    f

  • Dan Ebberts

    April 25, 2013 at 9:41 pm

    I haven’t tested it, but that looks about right. So you end up with the frame number where the latest transition occured. If you convert that to time and subtract it from the current time, that will give you how far along in your animation you should be.

    Dan

  • Sean Mcclintock

    April 25, 2013 at 9:44 pm

    Yeah, works like a charm. Thanks again Dan.

    targetLayer =thisComp.layer("Controls").effect("B&W Map")("Layer")
    samplePoint = transform.position
    sampleRadius = [1,1];
    above = false;

    for (f = timeToFrames(inPoint);
    f<= timeToFrames(); f++){
    t = framesToTime(f);
    sampledColor_8bpc = 255 * targetLayer.sampleImage(samplePoint, sampleRadius,true,t);
    R = Math.round(sampledColor_8bpc[0]);

    if (R<1 ){ above = true; break;
    }
    }

    if (above) time - t else 0
    ;

  • Sean Mcclintock

    April 26, 2013 at 6:17 pm

    Everything is working but I (seemingly randomly) keep getting an After Effects error: unsafe operation attempted ( 58 :: 0 ). Occurs in a loop which effectively crashes After Effects. Do I need to put in some sort of if statement to check for something?

    targetLayer =thisComp.layer("Controls").effect("B&W Map")("Layer")
    samplePoint = transform.position
    sampleRadius = [1,1];
    above = false;

    for (f = timeToFrames();
    f>= timeToFrames(inPoint); f--){
    t = framesToTime(f);
    sampledColor_8bpc = 255 * targetLayer.sampleImage(samplePoint, sampleRadius,true,t);
    R = Math.round(sampledColor_8bpc[0]);

    if (R>1 ){
    above = true; break;
    }
    }

    if (above) time - t else 0
    ;

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