3 Replies Latest reply on Jul 22, 2009 1:28 PM by Adolfo Rozenfeld

    Changing a keyframe value with an expression ?

    TerrificOn

      Hi all, i'd like to know if its possible to change a keyframe value (lets say in the rotation) with an expression.

       

      i know i can access the value with effect("CC Cylinder")(10).key(4).value but its a read-only expression. i cant assign my own value to it ...key(4).value = something.

       

      the purpose of this would be to allow someone to change the number of rotations the ball has to do by only setting the opacity of a null to the number of turn desired (using the thisComp.layer("NbTour").transform.opacity as an input). it would prevent mistakes like moving a keyframe and changing the animation and would also allow to do multiple version easily (i have 40 versions to do with different amount of turns...)

       

      thanks a lot !

      .Eric

        • 1. Re: Changing a keyframe value with an expression ?
          Adolfo Rozenfeld Adobe Employee

          Eric:

          While you can't actually change the value stored in a keyframe with expressions, for all practical purposes you can write an expression that produces the same result. For example, if the keyframe index is 4, then go from the previous keyframe value to to the value specified in a Slider or Dial expression control effect (or opacity of a null, but why bother?), for example.

           

          But also you can make this work without keyframes at all.

          You just add a Dial expression control effect and add an expression like this to the layer's rotation.

           

          Revols = (drag with the pickwhip towards the dial effect's parameter).

          ease(time, 0, 5, 0, Revols*360);

           

          What this expression would do is, as time goes from 0 to 5 seconds (use your own timings), rotation will go from 0 to the number of revolutions specified by the user in the dial.

          • 2. Re: Changing a keyframe value with an expression ?
            TerrificOn Level 1

            Wow thanks for the fast answer !

             

            I'm using the opacity of a null because it cant be seen and can be accessed directly from the layers, also because i didnt know about the expressions controls (been playing with that since yesterday so...)

             

            can i set the time with frames instead of seconds ?

            *** Figured it out myself : ease(time, (12/24), (108/24), -9, Revols*-360);

            *** ease(time, (frameNumber/framePerSeconds)...

             

            And can i use this command to do multiple animations on the same object ? like turning once on the right, then 2 times left etc... ?

             

            thank you again !

            • 3. Re: Changing a keyframe value with an expression ?
              Adolfo Rozenfeld Adobe Employee

              First, your question about making it linear.

              linear(time, 0, 5, 0, Revols*360)

              Would that be good enough?

               

              linear() and ease() are range converting methods. In other words, they adapt a range into another.

              For example suppose you want the opacity of a layer to drive position y of the same layer (in a, say, NTSC sized comp). The problem is, the useful range for opacity goes from 0 to 100 and for position y would want to scale it to the 0-480 range.

               

              So, you could have this expression in position:

               

              convert = linear(transform.rotation, 0, 360, 0, 480);

              [position[0], convert]

               

               

              And can i use this command to do multiple animations on the same object ? like turning once on the right, then 2 times left etc... ?

               

              It wouldn't be the ideal way to do it.

              The ideal way depends on what you want to achieve specifically, because otherwise you just use keyframes

               

              can i set the time with frames instead of seconds ?

               

              Coming up with your own solution is the best possible thing. Congrats.

              FWIW, there's a framesToTime function:

               

              So, supposed a variable called myframes is connected to a slider control with your desired frames value.

              framesToTime(myframes) will convert frames to time.

               

              There's also the opposite, timeToFrames()

              1 person found this helpful