A simple Position change to a 3D layer

Scripting for After Effects

A simple Position change to a 3D layer

Postby andynick on 02/1/2017, 10:42 pm

Hey all -
I'm very new to expressions, although I was an Actionscript developer in another life. It's very frustrating to me when I feel like something very simple should work, so instead of banging my head against my desk, I thought I'd turn to my favorite community.

I want to change the x, y, and z position values of a comp.

I need it's position to match a nested comp's position -- with some static offsets.

Eventually, I'll add some math that moves its y position at a fraction of the speed... but first, I have to get this syntax right.

comp("BG").layer("BG_mover").transform.position + [-1120,-10564,-3000]


x_offset = -1120
y_offset = -10564
z_offset = -3000

newX = x + x_offset
newY = y + y_offset
newZ = z + z_offset

[newX, newY, newZ]

The error I get:
"Error at 11 in property 'Position' of layer 105 ("FG") in comp 'MAIN'.
property or method name 'undefined' in Class 'Number' is missing or does not exist. It may have been renamed, moved, deleted, or the name may have been mistyped."

I tried removing ".value"
I tried simplifying in a bunch of ways.
Someone please tell me that I'm missing something simple.

Thanks in advance!!!
Posts: 12
Joined: 06/1/2011, 1:55 pm

Re: A simple Position change to a 3D layer

Postby ender772 on 02/3/2017, 2:22 pm

well i should probably direct you to the 3d stroke expression tutorial found on this same site...but its really just 10 minutes of setup then he gives us this expression..
x=(thisComp.layer("Null 1").transform.position[0]-thisComp.width/2;

y=(thisComp.layer("Null 1").transform.position[1]-thisComp.height/2;

z=(thisComp.layer("Null 1").transform.position[2];

I dont know anything about expressions but yours looked like this so i thought it might help..
Posts: 403
Joined: 04/19/2013, 3:52 pm

Re: A simple Position change to a 3D layer

Postby Laserschwert on 02/21/2017, 3:46 am

It looks like as soon as there's a line with more going on than just setting a fixed value as a variable, you have to end the line with a semi-colon. So this works:

Code: Select all

x_offset = -10
y_offset = -100
z_offset = -300

newX = x + x_offset;
newY = y + y_offset;
newZ = z + z_offset;

[newX, newY, newZ]
Posts: 38
Joined: 09/8/2008, 2:30 pm

Re: A simple Position change to a 3D layer

Postby andynick on 02/21/2017, 12:19 pm

Much appreciated. In Actionscript, semicolons are optional --- so I have some baaaaaad habits to break.

Thanks again!
Posts: 12
Joined: 06/1/2011, 1:55 pm

Return to After Effects Expressions