Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Mask Path expression

  • Mask Path expression

  • Dan Kelly

    August 9, 2012 at 2:10 pm

    I need an expression to turn a mask’s opacity = 100 if there’s a mask path keyframe, else the mask opacity = 0. I have some code background but this is my very first expression, so be gentle.

    Can the presence of a keyframe be tested?

    Thanks for any and all help!

    Dan

    Here’s the background

    I’m doing roto with Mocha AE and bringing in the shape layers via “Paste Mocha Mask”. The in and out points of the shape layers get translated into AE masks as continuous mask shape keyframes, starting at the shape in point and ending at the shape outpoint. This means that all the masks are visible and that’s not very useful, so my idea is to knock out the opacity to recreate in and out points. If anyone is familiar with this workflow and thinks they have a better solution than writing an expression, I’d be much obliged.

    if (mask("Mask 1").maskPath){mask("Mask 1").opacity = 100}else{mask("Mask 1").opacity = 0
    }

  • Dan Ebberts

    August 9, 2012 at 2:17 pm

    This should work:

    if (thisProperty.propertyGroup(1).maskPath.numKeys > 0) 100 else 0

    Dan

  • Dan Kelly

    August 9, 2012 at 2:54 pm

    Thanks Dan,

    Started my quest on your site, small world! I pasted into the Mask Opacity expression but no go. Mask opacity stays at 100. Am I missing something?

  • Dan Ebberts

    August 9, 2012 at 3:14 pm

    From your screen shot, it looks like there are Mask Path keyframes, so I would expect the expression to return 100%. I notice that there appear to be refresh issues in versions prior to CS6, which means you might have to clear the cache to see a change. It’s also possible I misunderstood your request. The expression should give you 100% if the path has any keyframes. Is that what you wanted?

    Dan

  • Dan Kelly

    August 9, 2012 at 3:23 pm

    [Dan Ebberts] “The expression should give you 100% if the path has any keyframes. Is that what you wanted?”

    opacity = 100 when there is a mask path keyframe and 0 when there is not, for every frame.

    CS6 has issues with paste mocha mask which is why I’m working in CS 5.5 for now. I’ll try in 6.0…

  • Dan Ebberts

    August 9, 2012 at 3:34 pm

    > for every frame.

    Do you mean that you only want the opacity to be 100% at frames that have corresponding keyframes on the path?

    Dan

  • Dan Kelly

    August 9, 2012 at 3:48 pm

    Yes! and 0 when there are no keyframes on the path.

    The functionality I need is to have the absence/presence/absence of Mask Path keyframes flip opacity of the mask from 0 to 100 to 0.

  • Dan Ebberts

    August 9, 2012 at 3:54 pm

    I can think of a couple ways to do it. If you really want 100 on any frame where there is a keyframe, on each frame, the expression will have to go through all the keyframes until it finds one that has the same frame number as the current time (= pretty inefficient if you have a lot of keyframes.

    The other possibility would be to just check the times of the first and last keyframes, and make the opacity 100 if the current time is between those two times. Will that work?

    Dan

  • Dan Kelly

    August 9, 2012 at 4:11 pm

    [Dan Ebberts] The other possibility would be to just check the times of the first and last keyframes, and make the opacity 100 if the current time is between those two times. Will that work?”

    Either one would work. Paste Mocha Mask creates only one contiguous set of keyframes for each mask, so the first and last approach makes sense.

  • Dan Ebberts

    August 9, 2012 at 4:17 pm

    Try this:


    p = thisProperty.propertyGroup(1).maskPath;
    if (p.numKeys > 0){
    t1 = p.key(1).time;
    t2 = p.key(p.numKeys).time;
    if (time >= t1 && time <= t2) 100 else 0
    }else
    0

    Dan

Viewing 1 - 10 of 11 posts

Log in to reply.

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