Answers.Body: <p><strong>Short answer</strong>: no. </p>
  
  <p><strong>Long answer</strong>: There may be an unknown, undocumented hack that enables this, like modifying some of the core classes, or a workaround, like writing to a file and reading the results, but I've never heard of such a thing.</p>
  
  <p>You probably know this, but it might be worth spelling out the differences between the two.</p>
  
  <p>Expressions are evaluated every time a frame is rendered, either during preview or final render (this can be multiple times per frame when motion blur is turned on). They can access the properties of layers and compositions and other project items, as well as making some system calls and <a href="https://blob.pureandapplied.com.au/using-data-from-an-external-file-to-drive-expressions/" rel="nofollow noreferrer">reading external files</a> and a few other undocumented JS functions like <a href="https://blob.pureandapplied.com.au/huh-lookit-that-you-can-auto-insert-the-date-in-an-expression/" rel="nofollow noreferrer">time and date</a>. They can not change any part of the project, they are limited to returning one value—the value applied to the property they belong to.</p>
  
  <p>This is different to the way scripts work, which is to basically replicate anything the user could do, but programatically. They are not called at render time. Since scripts can change the content of compositions, there would be problems with calling them at render time: just using your example, the alert might be displayed 64 times <em>per frame</em> if motion blur was set really high—that would get old pretty quickly. But even for a non-trivial example: suppose you had a script that added a layer to the current comp. If it was called from an expression it would run every time the frame was rendered, whether it was at final render time, or during previewing, or when the user parked the playhead on the frame. With MB on that could mean 64 new layers could be added per frame—<em>while the comp was being rendered</em>. The results would get pretty messy.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-10T05:05:25.450Z
Answers.LastActivityDate: 2018-12-10T06:09:26.160Z
Answers.LastEditDate: 2018-12-10T06:09:26.160Z
Answers.UserDisplayName: stib
Answers.Body: <p>You can read/write the expressions from ExtendScript ;)
  For example for changing placeholders:</p>
  <pre><code>var propertyExpression = property.expression;
  if (property.expressionEnabled &amp;&amp; propertyExpression) {
    try {
      property.expression = propertyExpression.replace(new RegExp(placeholder, 'g'), 'string for replacement');
    } catch(e) {
    }
  }
  </code></pre>
  <p>I had to make 6 nested loops to get into all expressions...
  (The layers have properties, which have sub properties, which also have sub properties, ...)</p>
  <p>So I guess you can insert <code>alert(&quot;stuff&quot;)</code> directly into an expression.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-30T13:41:32.247Z
Answers.LastActivityDate: 2022-08-30T13:41:32.247Z
Answers.UserDisplayName: Guntram
Body: <p><strong>Backstory</strong></p>
  
  <p>I'm trying to learn about After Effects' different abilities.</p>
  
  <p><strong>Question</strong></p>
  
  <p>If I make a function using extend script like so</p>
  
  <pre><code>function alertStuff() {
      alert("stuff")
  }
  </code></pre>
  
  <p>Can I call this using a layer expression?</p>
  
  <pre><code>alertStuff();
  </code></pre>
  
Tags: <after-effects-expressions><after-effects-scripting>
Title: After Effects - Can Expressions read from Extend Script?
UserDisplayName: Jacksonkr
ThreadText: # After Effects - Can Expressions read from Extend Script?
  
  (Asked by: username_0 on 2018-12-06)
  
  **Backstory**
  
  I'm trying to learn about After Effects' different abilities.
  
  **Question**
  
  If I make a function using extend script like so
  
  ```
  function alertStuff() {
      alert("stuff")
  }
  
  ```
  
  Can I call this using a layer expression?
  
  ```
  alertStuff();
  
  ```
  
  **Tags:** after-effects-expressions, after-effects-scripting
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-12-10. Score: 1 | Accepted answer
  
  **Short answer**: no.
  
  **Long answer**: There may be an unknown, undocumented hack that enables this, like modifying some of the core classes, or a workaround, like writing to a file and reading the results, but I've never heard of such a thing.
  
  You probably know this, but it might be worth spelling out the differences between the two.
  
  Expressions are evaluated every time a frame is rendered, either during preview or final render (this can be multiple times per frame when motion blur is turned on). They can access the properties of layers and compositions and other project items, as well as making some system calls and [reading external files](https://blob.pureandapplied.com.au/using-data-from-an-external-file-to-drive-expressions/) and a few other undocumented JS functions like [time and date](https://blob.pureandapplied.com.au/huh-lookit-that-you-can-auto-insert-the-date-in-an-expression/). They can not change any part of the project, they are limited to returning one value—the value applied to the property they belong to.
  
  This is different to the way scripts work, which is to basically replicate anything the user could do, but programatically. They are not called at render time. Since scripts can change the content of compositions, there would be problems with calling them at render time: just using your example, the alert might be displayed 64 times *per frame* if motion blur was set really high—that would get old pretty quickly. But even for a non-trivial example: suppose you had a script that added a layer to the current comp. If it was called from an expression it would run every time the frame was rendered, whether it was at final render time, or during previewing, or when the user parked the playhead on the frame. With MB on that could mean 64 new layers could be added per frame—*while the comp was being rendered*. The results would get pretty messy.
  
  
  ---
  
  ### Answer by username_2 on 2022-08-30. Score: 0
  
  You can read/write the expressions from ExtendScript ;)
  For example for changing placeholders:
  
  ```
  var propertyExpression = property.expression;
  if (property.expressionEnabled && propertyExpression) {
    try {
      property.expression = propertyExpression.replace(new RegExp(placeholder, 'g'), 'string for replacement');
    } catch(e) {
    }
  }
  
  ```
  
  I had to make 6 nested loops to get into all expressions...
  (The layers have properties, which have sub properties, which also have sub properties, ...)
  
  So I guess you can insert `alert("stuff")` directly into an expression.
  
  
  ---
  
  