ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Simple expression to clamp height scale?

FAQ   •   VIEW ALL
 Simple expression to clamp height scale? on Jul 9, 2018 at 4:25:25 pm

Hi all;

I know this must be an easy solution for anyone who knows how to write expressions-- I'm still at the stage where I'm able to mess around with some pre-written expressions but not sure how to write them myself.

All I want to do is "lock" or clamp the Y (or height scale) of a shape layer so that the value cannot be changed even if you try to change it.
I want to still change the width or x scale though.

So far whenever I try to use the clamp expression it only ever works for the width, not the height-- can someone help me out here? I know I'm doing something wrong, I'm just too clueless to even know what that is.

 Re: Simple expression to clamp height scale?on Jul 9, 2018 at 7:05:07 pm

set 999 to whatever you want it to be locked to.

`[value[0],999]`

 Re: Simple expression to clamp height scale?on Jul 9, 2018 at 7:09:17 pm

Perfect!! And wow, even more simple than I thought! are the brackets around the 0 the reason why the width is still editable? (I want to learn, so might as well ask)

Thank you so much though, I really do appreciate it.

 Re: Simple expression to clamp height scale?on Jul 9, 2018 at 8:12:58 pm

No, the brackets around 0 are for declaring the initial value for X.

Something like scale the property requires two different values (X and Y).
It is declared with an array, like this [X,Y].
Arrays separate cells with a comma between elements.

if you wanted to reference the initial value, it would be 'value', or, you could expand it like this:
[value[0],value[1]]
The brackets at the end of a variable (value here) tell it to look at the first cell of the array.
Which would declare creating a new array, using value[array0],value[array1]. Arrays always start at integer 0.

So, first we need an array for scale:
`[`
then, we want to access the initial value where x is stored:
`[value[0]`
add a comma to declare the end of cell value 0, and beginning cell value 1:

Then, we want to force Y to be an integer of our choice (e.g., 999):
```[value[0],999] That's it! You could also do something more complex as well, such as: <code>[value[0]/10,(value[0]*1.5)+value[1]]```

So really, the brackets are just for declaring something is an array.

 Re: Simple expression to clamp height scale?on Jul 9, 2018 at 9:15:41 pm

Wow, thank you so much for replying. I am always trying to learn more, but trying to wrap my mind around the basics of expression writing has always been challenging (even when im looking at things that break it down! It's very similar to math formulas in my mind, which I always had a hard time with as well).

Somehow you managed to break it down in a way that I now understand it. I didn't even know what an array was even though I have sat there reading about the basics of arrays and values etc multiple times. It never clicked until now....so I really do mean it when I say I appreciate your response. You taught me a valuable lesson!

(apologies if the next paragraph doesn't use the right terminology or doesn't quite make sense...I tried haha)
I think the reason why I was confused is because I thought the 0 was the start of the array basically--- so for some reason I thought value was a uh...command? (similar to if i were to write clamp), and the 0 was the x scale all by itself, since it was followed by the y scale number. Now I see that value isn't a command at all(which it can't be if it's in brackets aka an array right?), but THATS what is actually the x scale itself(not the 0), and the 0 is what tells ae that "value" is the width and not something else. And value is written instead of a number because I want to be able to still change it, whereas y is the number itself because I want it locked. Honestly I know this is probably a terrible explanation but I am writing it out anyways in case my understanding is wrong, and also because it helps drive the lesson home for me.

I do have one more follow up question though. I typed in [20,50] into the expression box for scale-- and it changed the width to 20, and the height to 50....why is it that we have to define value as value[0] (the zero being the width aka x value, right? My terminology may be off) but we don't have to define the 20 (so that it would look like [20[0], 50])? You don't have to answer-- but I'm curious now if maybe I'm just not understanding it right.

(sorry for the wall of text....but also THANK YOU AGAIN FOR YOUR RESPONSE!! I know this is like.......sooooo basic but it really is helping so THANK YOU!!)

 Re: Simple expression to clamp height scale?on Jul 9, 2018 at 10:42:04 pm

It is because the [0] is used to call the first part of value, which in this case is an array. Value is the number that goes into the expression BEFORE the code. Value are the numbers that you can type in or arrow change initially, or rotate/reposition with the mouse. Position has 2 parts of a value (unless separated), rotation has 1, scaled has 2, opacity has 1, etc.

So we are saying "look at the initial position (value). Only pay attention to the X part of that input array (value[0]). Now build that into a new output array ([value[0], ]...), But for the second part (Y), just be this particular number:999 ([value[0],999]).

If you say [20,50], you're telling the output to just be 20X, and 50Y. Ignore value all together.

The brackets are used to build or reference arrays (in this case, value). You are building a new array as an output to replace the original one (value). Note that if you try to put a single output (eg, '100' or [100]), you will get an error saying the system is expecting a number of two dimensions (2 units long of an array, or [X,Y])