Home Forums After Effects Expressions Explore the clamp() Expression

Viewing 0 reply threads
  • Author
    Posts
    • Nubby Ninja
      Keymaster
      Post count: 13

      Some properties and expressions have a maximum value of 100, and a minimum value of 0.
      An example of one that does not have these limitations is position. Position can be negative values on the x, y, and z axis.
      Opacity is one property that cannot be a negative value. It ranges from 0-100.

      When writing expressions for sliders, it’s easy to overlook this. Then you try to use the slider, take it to a value beyond 100, and it generates an error.

      In order to prevent these annoying errors, we can do a couple of things. We can write a statement that manages the error, or silences it; or we can prevent the error by using the clamp() expression.

      Once you’ve already configured your sliders and everything seems to be working, go to your slider, hold ALT and click the stopwatch of the property you want to clamp. In this case it was Smoothing Amount.

      Paste the following:

      clamp(value,0,100);

      That’s it. It reads the current value, and clamps it to a range of 0 to 100.

      Attachments:
      You must be logged in to view attached files.

      Nubby Ninja

Viewing 0 reply threads
  • You must be logged in to reply to this topic.