user8018: Is it possible to just move a layer along one axis, eg x?
I need to move many layers individually in a 3D space, but only along one axis. It would be much quicker if I could lock all axis but one, and then move along that.

user38839: You can also just separate the dimensions, add an expression to each axis you want to lock and type in 0 (or wherever you want the position locked) in the expression field.


user4426: You can move any object by dragging on the Position coordinates in the object's timeline.

Alternatively, you can constrain to a single dimension when moving an object in the canvas by putting your cursor over the appropriately coloured arrow (R, G, B, = x, y, z).  Wait for your cursor to show a letter next to it, then drag the object.


user1950: It's easy to do with a quick expression:
Alt/Option-click the stop watch for the position property. You'll see the default expression transform.position is automatically inserted. The position property is an array – it contains the X, Y and Z value components. We want to lock it so that only one of the values can change. So we have to pick the array apart into its components, and then create a new array using some constant values.
So say we want to lock the layer to movement only on the X axis. We'll use the X component of the transform.position array and then put in a constant value for the Y and Z components. Say the layer's Y position is 123 and its Z position is 345. We'd use this expression:
[transform.position[0], 123, 345]

note that the enclosing square brackets are part of the expression - they turn the three values back into an array. The bit where it says transform.position[0] selects just the first component of the array (just to be annoying, most computer languages count array components from 0, so the first component is [0], the second [1] and so on).
You could refine this to make the layer easier to edit:
[transform.position[0], transform.position.valueAtTime(0)[1], transform.position.valueAtTime(0)[2]]

here transform.position.valueAtTime(n) is a function that returns the value of the position property at time n. The round brackets are the input to the function, in this case the start of the comp or 0. Then as we want just one part of the position, we then use the square brackets to stipulate which bit: [1] for Y and [2] for Z (remember [1] means the second value in the array and [2] means the third). So the layer will be locked to the Y and Z position it has at the start of the comp, and will be free to move on the X position.
To do the same with the Y position or the Z, or the scale, or rotation or whatevs, you just use the same form, but change the array index (the number in the square brackets). So to lock the movement to only the Y axis:
[transform.position.valueAtTime(0)[0], transform.position[1], transform.position.valueAtTime(0)[2]]

or Z axis:
[transform.position.valueAtTime(0)[0], transform.position.valueAtTime(0)[1], transform.position[2]]

By now you should see the pattern.
Note that for 2D layers, the array only has two components, so you'd leave out the third part altogether, so to lock a 2D layer to the X axis you'd use:
[transform.position[0], transform.position.valueAtTime(0)[1]]

Expressions are your friend!

8018: <p>Is it possible to just move a layer along one axis, eg <code>x</code>?</p>

<p>I need to move many layers individually in a 3D space, but only along one axis. It would be much quicker if I could lock all axis but one, and then move along that.</p>
 38839: <p>You can also just separate the dimensions, add an expression to each axis you want to lock and type in 0 (or wherever you want the position locked) in the expression field.
<a href="https://i.stack.imgur.com/YIxYG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YIxYG.png" alt="Here you see the z axis is locked" /></a></p>
 4426: <p>You can move any object by dragging on the Position coordinates in the object's timeline.</p>

<p><img src="https://i.stack.imgur.com/PPLJ2.png" alt="enter image description here"></p>

<p>Alternatively, you can constrain to a single dimension when moving an object in the canvas by putting your cursor over the appropriately coloured arrow (R, G, B, = x, y, z).  Wait for your cursor to show a letter next to it, then drag the object.</p>

<p><img src="https://i.stack.imgur.com/NhHes.jpg" alt="enter image description here"></p>
 1950: <p>It's easy to do with a quick expression:</p>

<p><kbd>Alt/Option</kbd>-click the stop watch for the position property. You'll see the default expression <strong><em>transform.position</em></strong> is automatically inserted. The position property is an array – it contains the X, Y and Z value components. We want to lock it so that only one of the values can change. So we have to pick the array apart into its components, and then create a new array using some constant values.</p>

<p>So say we want to lock the layer to movement only on the X axis. We'll use the X component of the <strong><em>transform.position</em></strong> array and then put in a constant value for the Y and Z components. Say the layer's Y position is 123 and its Z position is 345. We'd use this expression:</p>

<pre><code>[transform.position[0], 123, 345]
</code></pre>

<p>note that the enclosing square brackets are part of the expression - they turn the three values back into an array. The bit where it says <strong><em>transform.position[0]</em></strong> selects just the first component of the array (just to be annoying, most computer languages <a href="https://stackoverflow.com/questions/7320686/why-does-the-indexing-start-with-zero-in-c">count array components from 0</a>, so the first component is <strong>[0]</strong>, the second <strong>[1]</strong> and so on).</p>

<p>You could refine this to make the layer easier to edit:</p>

<pre><code>[transform.position[0], transform.position.valueAtTime(0)[1], transform.position.valueAtTime(0)[2]]
</code></pre>

<p>here <strong><em>transform.position.valueAtTime(n)</em></strong> is a function that returns the value of the position property at time <em>n</em>. The round brackets are the input to the function, in this case the start of the comp or 0. Then as we want just one part of the position, we then use the square brackets to stipulate which bit: <strong><em>[1]</em></strong> for Y and <strong><em>[2]</em></strong> for Z (remember <strong><em>[1]</em></strong> means the second value in the array and <strong><em>[2]</em></strong> means the third). So the layer will be locked to the Y and Z position it has at the start of the comp, and will be free to move on the X position.</p>

<p>To do the same with the Y position or the Z, or the scale, or rotation or whatevs, you just use the same form, but change the array index (the number in the square brackets). So to lock the movement to only the Y axis:</p>

<pre><code>[transform.position.valueAtTime(0)[0], transform.position[1], transform.position.valueAtTime(0)[2]]
</code></pre>

<p>or Z axis:</p>

<pre><code>[transform.position.valueAtTime(0)[0], transform.position.valueAtTime(0)[1], transform.position[2]]
</code></pre>

<p>By now you should see the pattern.</p>

<p>Note that for 2D layers, the array only has two components, so you'd leave out the third part altogether, so to lock a 2D layer to the X axis you'd use:</p>

<pre><code>[transform.position[0], transform.position.valueAtTime(0)[1]]
</code></pre>

<p>Expressions are your friend!</p>
