Answers.Body: <p>You can't put the expression on a null object, but you can use a text layer.</p>
  
  <p>Following @bobtiki's <code>eval()</code> tip I tried using the source text of a text layer and running <code>eval()</code> on it. Initially I had no success, I was getting an <strong>"object of type TextProperty found where a Number, Array or Property is needed"</strong> error. But if I put something like a number on its own in the text layer and treated the source text like an array I <em>could</em> get it, I just wasn't able to access a whole string.</p>
  
  <p>I was about to give up, then I remembered from doing extendscript scripting that you get the raw value of an AE property object using the javascript property <code>.value</code>*.</p>
  
  <p>So after a bit of fiddling around with quotes and escaping (neither are needed, thank heavens) I got it to work. </p>
  
  <p><strong>TL;DR: Here is how you reference an expression that is written in a text layer's source</strong>, without having to save external files:</p>
  
  <pre><code>var theExpression = thisComp.layer("your text layer").text.sourceText.value;
  eval(theExpression);
  </code></pre>
  
  <p>And then you write the expression into the text layer, in this case called "your text layer". This is really cool! It even updates in real time <strong>as you're typing the expression</strong>!</p>
  
  <p>Here's a comp with the position of the cyan layers being driven by the expression you see on the text layer. If I duplicate one of the cyan layers its position is calculated individually based on the random seed <code>index</code>, and if I change the expression, they all update!</p>
  
  <p><a href="https://i.sstatic.net/MiUZY.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MiUZY.png" alt="enter image description here"></a>
  I'm stoked, this was the best question ever!</p>
  
  <p>* <em>this sentence sounds like gibberish I know. The problem is that AE layers' property's values are JavaScript objects, and as such they have JavaScript properties, and one of the AE property's value's JavaScript properties is the <code>value</code> property which represents the raw value of the AE property. And the value of the AE source text property is an object which must include formatting and whatnot, and so it is different to the text.sourceText.value value. Confused?</em></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-21T15:03:02.403Z
Answers.Text: Using a text layer works PERFECTLY for what I am trying to accomplish! Thank you!
Answers.UserDisplayName: Ben Mora
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-23T03:32:01.360Z
Answers.Text: Thanks. I've written it up as a post on my blog http://wp.me/p6MMUE-3K </shamelessselfpromotion>
Answers.UserDisplayName: stib
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-20T03:53:37.943Z
Answers.LastActivityDate: 2016-07-20T05:42:34.273Z
Answers.LastEditDate: 2016-07-20T05:42:34.273Z
Answers.UserDisplayName: stib
Answers.Body: <p>Yes, since expressions are basically JavaScript, you can load and evaluate external source files. Unfortunately the location needs to be hard-coded, since (AFAIK) expressions do not have access to the path of your AE project, so it's rather brittle. For instance:</p>
  
  <pre class="lang-js prettyprint-override"><code>try {
      myPath = "~/Desktop/source.js";
      $.evalFile(myPath);
  } catch(err) {
      "MISSING";
  }
  </code></pre>
  
  <p>Further explanation of how similar code works can be seen <a href="http://www.provideocoalition.com/expression_shorts_-_read_external_text_document/" rel="nofollow">on the ProVideoCoalition site</a>.</p>
  
  <p>One further caveat is that the script is loaded and evaluated again for every frame that gets rendered. You might want to test how loading the script affects your render times.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-14T17:26:26.667Z
Answers.LastActivityDate: 2016-07-15T12:21:45.393Z
Answers.LastEditDate: 2016-07-15T12:21:45.393Z
Answers.UserDisplayName: swizzlevixen
Body: <p>I am going to have tons of layers use the same expression, but I need to be able to edit the expression later without having to edit it for every layer. I also can't simply have each layer's property point to the original, because the expression needs to be evaluated for each layer relative to itself.</p>
  
  <p>Is there a way I can have each layer expression simply point to and parse a text file? I could edit the text file so all layers expressions update.
  Or, if somehow I could put the expression on a null object and have each layer parse that expression for itself.
  Thanks for any help!</p>
  
  <p>My workaround solution is to make a null object with a slider control for every single value that I may edit later, updating all layers, but this doesn't allow me to change the non-numerical information in the expression, such as adding parenthesis or other functions.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-20T03:19:48.267Z
Comments.Text: Sounds like a job for the extendscript toolkit.
Comments.UserDisplayName: stib
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-07-20T03:21:35.237Z
Comments.Text: When I'm dealing with large numbers of layers using expressions the workaround I use is to give the layers that share expressions the same colour label. So then when you edit the expression you just copy, right-click>select label group, then paste.
Comments.UserDisplayName: stib
Tags: <after-effects><after-effects-expressions>
Title: Can an expression parse a text file or the expression of another property in After Effects?
UserDisplayName: Ben Mora
ThreadText: # Can an expression parse a text file or the expression of another property in After Effects?
  
  (Asked by: username_0 on 2016-07-13)
  
  I am going to have tons of layers use the same expression, but I need to be able to edit the expression later without having to edit it for every layer. I also can't simply have each layer's property point to the original, because the expression needs to be evaluated for each layer relative to itself.
  
  Is there a way I can have each layer expression simply point to and parse a text file? I could edit the text file so all layers expressions update.
  Or, if somehow I could put the expression on a null object and have each layer parse that expression for itself.
  Thanks for any help!
  
  My workaround solution is to make a null object with a slider control for every single value that I may edit later, updating all layers, but this doesn't allow me to change the non-numerical information in the expression, such as adding parenthesis or other functions.
  
  **Tags:** after-effects, after-effects-expressions
  
  > **Comments:**
  > **username_1**: Sounds like a job for the extendscript toolkit.  
  > **username_1**: When I'm dealing with large numbers of layers using expressions the workaround I use is to give the layers that share expressions the same colour label. So then when you edit the expression you just copy, right-click>select label group, then paste.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-07-20. Score: 2 | Accepted answer
  
  You can't put the expression on a null object, but you can use a text layer.
  
  Following @bobtiki's `eval()` tip I tried using the source text of a text layer and running `eval()` on it. Initially I had no success, I was getting an **"object of type TextProperty found where a Number, Array or Property is needed"** error. But if I put something like a number on its own in the text layer and treated the source text like an array I *could* get it, I just wasn't able to access a whole string.
  
  I was about to give up, then I remembered from doing extendscript scripting that you get the raw value of an AE property object using the javascript property `.value`\*.
  
  So after a bit of fiddling around with quotes and escaping (neither are needed, thank heavens) I got it to work.
  
  **TL;DR: Here is how you reference an expression that is written in a text layer's source**, without having to save external files:
  
  ```
  var theExpression = thisComp.layer("your text layer").text.sourceText.value;
  eval(theExpression);
  
  ```
  
  And then you write the expression into the text layer, in this case called "your text layer". This is really cool! It even updates in real time **as you're typing the expression**!
  
  Here's a comp with the position of the cyan layers being driven by the expression you see on the text layer. If I duplicate one of the cyan layers its position is calculated individually based on the random seed `index`, and if I change the expression, they all update!
  
  [![enter image description here](https://i.sstatic.net/MiUZY.png)](https://i.sstatic.net/MiUZY.png)
  I'm stoked, this was the best question ever!
  
  \* *this sentence sounds like gibberish I know. The problem is that AE layers' property's values are JavaScript objects, and as such they have JavaScript properties, and one of the AE property's value's JavaScript properties is the `value` property which represents the raw value of the AE property. And the value of the AE source text property is an object which must include formatting and whatnot, and so it is different to the text.sourceText.value value. Confused?*
  
  > **Comments:**
  > **username_0**: Using a text layer works PERFECTLY for what I am trying to accomplish! Thank you!  
  > **username_1**: Thanks. I've written it up as a post on my blog http://wp.me/p6MMUE-3K </shamelessselfpromotion>  
  
  ---
  
  ### Answer by username_2 on 2016-07-14. Score: 3
  
  Yes, since expressions are basically JavaScript, you can load and evaluate external source files. Unfortunately the location needs to be hard-coded, since (AFAIK) expressions do not have access to the path of your AE project, so it's rather brittle. For instance:
  
  ```js
  try {
      myPath = "~/Desktop/source.js";
      $.evalFile(myPath);
  } catch(err) {
      "MISSING";
  }
  
  ```
  
  Further explanation of how similar code works can be seen [on the ProVideoCoalition site](http://www.provideocoalition.com/expression_shorts_-_read_external_text_document/).
  
  One further caveat is that the script is loaded and evaluated again for every frame that gets rendered. You might want to test how loading the script affects your render times.
  
  
  ---
  
  