Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Invert 1 Key Frame Value With A Checkbox?

  • Invert 1 Key Frame Value With A Checkbox?

    Posted by Chad Gilmour on February 2, 2012 at 5:28 pm

    I couldn’t find an answer to this, but expression language is still pretty difficult for me to grasp.

    I have 2 key frames and I want to be able to invert the value of the first keyframe by clicking a checkbox. The keyframes will never move along the timeline. I attached a still to help illustrate my question. I’m not very good with expressions and would really appreciate it if I got some help spelling this thing out.

    Thanks!

    Paul Roper replied 14 years, 3 months ago 2 Members · 6 Replies
  • 6 Replies
  • Paul Roper

    February 2, 2012 at 6:15 pm

    Put this in your rotation expression:

    if(effect("Reverse animation")("Checkbox")==1)
    {
    -value
    }
    else
    {
    value
    }

  • Paul Roper

    February 2, 2012 at 6:30 pm

    ….although this will invert all your keyframes, unless you keyframe the invert control, ie. 1 frame before your second keyframe, set “Reverse Animation” checkbox to OFF, then on your second rotate keyframe, set it to ON.

    Obviously there will be only 1 frame from inverted to positive; the movement will not be smooth. But that’s what you get with checkboxes – they’re either on or off.

  • Chad Gilmour

    February 2, 2012 at 6:33 pm

    Sweet! I got it to work by eliminating some of the carriage returns around “-value” and “value”.

    I think this “if/else” type of expression might open me up to some new things.

    Is there a place online that explains things like difference between using “( )” vs “[ ]” vs “{ }” and why you needed to use 2 equal signs instead of 1?

    Thanks again, I really appreciate your help.

  • Chad Gilmour

    February 2, 2012 at 6:41 pm

    My second keyframe value is 0 so no checkbox keyframing required. Good to know though! Is there way to only select a specific keyframe with markers or something?

  • Paul Roper

    February 2, 2012 at 7:38 pm

    Dan Ebberts (you’ll see a LOT of him in this expressions forum!) has a great site:

    https://www.motionscript.com/

    As for the brackets:

    () is normally used like you would in ordinary maths, eg. (2*3)+10 is not the same as 2*(3+10)….or as part of After Effects’ syntax of naming properties.

    [] is normally used for arrays, eg. the position property has two or three variables: [x,y,z] so to access just the x, you’d use: transform.position[0]
    to access the y, use
    transform.position[1]

    {} are for Javascript-type things, such as if…then statements. In the example I provided, the {} isolate the different things, eg:

    if (john_age > fred_age)
    {
    everything within
    these curly brackets
    happens if
    john is older than fred
    }
    else
    {
    everything in here
    happens
    no matter
    how long
    it
    rambles
    on
    for until you
    get to the close
    curly bracket
    }

    Hope that helps…I’m just kinda rambling while my Mac has a prolonged spinny-ball-of-death moment. Ah – it’s back to life!

    – Paul

  • Paul Roper

    February 2, 2012 at 7:42 pm

    ….oh and sometimes, when copying scripts from t’internet, it might help to first paste them into a text editor (TextEdit, Notepad, etc) and turn off all the formatting to get rid of any web/html/formatting weirdness, then copy from this and paste into after effects.

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