Skip to main content
Participating Frequently
October 6, 2023
Answered

Is there any destructuring support in After Effects Expressions

  • October 6, 2023
  • 1 reply
  • 377 views

I often do things with one value in an array property or want to separate them. Is there any way to use destructuring like in JavaScript to clean up my expressions so we don't have to declare multiple variables to separate them 

For instance instead of 

 

const elipseScaleX = content("Ellipse Path 1").size[0];
const elipseScaleY = content("Ellipse Path 1").size[1];

 

Javascript destructuring assignment would just be

 

const [elipseScaleX, elipseScaleY] = content("Ellipse Path 1").size;

 

That syntax doesn't seem to be supported in expressions though. Am I missing something in the docs or is there any plan to add support for this?

This topic has been closed for replies.
Correct answer JohnColombo17100380

Hi @dmsf,

Thanks for making this post! Destructuring is available when using the JavaScript expression engine (under File > Project Settings > Expressions). However, for properties there is a subtlety in that you will need to call ".value" on the property object in order for JavaScript to consider the property iterable and allow the destructuring assignment.

 

E.g. this will error with "TypeError: content is not iterable (cannot read property Symbol(Symbol.iterator))":

const [x, y] = content("Rectangle 1").content("Rectangle Path 1").size;

 

This will work as you're expecting:

const [x, y] = content("Rectangle 1").content("Rectangle Path 1").size.value;

 

I hope this helps!

 

Cheers,

- John, After Effects Engineering Team 

1 reply

JohnColombo17100380
Community Manager
JohnColombo17100380Community ManagerCorrect answer
Community Manager
October 6, 2023

Hi @dmsf,

Thanks for making this post! Destructuring is available when using the JavaScript expression engine (under File > Project Settings > Expressions). However, for properties there is a subtlety in that you will need to call ".value" on the property object in order for JavaScript to consider the property iterable and allow the destructuring assignment.

 

E.g. this will error with "TypeError: content is not iterable (cannot read property Symbol(Symbol.iterator))":

const [x, y] = content("Rectangle 1").content("Rectangle Path 1").size;

 

This will work as you're expecting:

const [x, y] = content("Rectangle 1").content("Rectangle Path 1").size.value;

 

I hope this helps!

 

Cheers,

- John, After Effects Engineering Team 

dmsfAuthor
Participating Frequently
October 7, 2023

Thanks John! Perfect. That's exactly the type error I was getting. Thank you!