Answers.Body: <p>The <code>sourceRectAtTime(n)</code> method does what it says on the tin: returns the dimensions of the <strong>source</strong> of a layer, at <strong>comp</strong> time <strong>n</strong>. So because the source of your layer is 1920px wide, it returns 1920.</p>
  
  <p>You want to be using another method, the <code>toComp</code> layer space transform. It returns the comp co-ordinates of a point in layer co-ordinates. To find where the top right (in layer co-ordinates it will be [0,0]) of a layer is you'd do</p>
  
  <pre><code>thisComp.layer("theLayerName").toComp([0,0]);
  </code></pre>
  
  <p>To find where the anchor point of a layer is in comp co-ordinates:</p>
  
  <pre><code>let theLayer = thisComp.layer("theLayerName");
  theLayer.toComp(theLayer.anchorPoint);
  </code></pre>
  
  <p>The really useful thing about toComp is that it works regardless of the parent chains that the layer may be connected to, and any transformations that have been applied.</p>
  
  <p>To apply it to your case apply this to the red's position property:</p>
  
  <pre><code>let white = thisComp.layer("white");
  let red = thisComp.layer("red");
  let sRect = white.sourceRectAtTime(time, true);
  let offset = white.toComp(sRect.width, sRect.top); //top right of the white layer
  value + offset; 
  </code></pre>
  
  <p><code>value</code> in the last line is a property that returns the currently set value of the layer property, after keyframes. So this will add the offset to whatever the position currently is.</p>
  
  <p>There is no need to use <code>time-white.inPoint</code> when calculating <code>sourceRectAtTime</code> because that method expects comp time as the first parameter, not layer time.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-06T12:39:19.183Z
Answers.LastActivityDate: 2020-06-06T12:39:19.183Z
Answers.UserDisplayName: stib
Body: <p>Here's the situation: I'm not new to After Effects. I've been using it for a while and I could say I'm an intermediate user. My knowledge is limited to everything but expressions.</p>
  
  <p>So, I have a <strong>white</strong> solid and a <strong>red</strong> solid. As the white solid increases width (scale), I want it to push the red solid. I'm not a newbie into programming, however, I'm either an advanced user. My guess on how to do it is the following one: get white's solid left and width properties from anchor point and add them to the X position of the red solid (<code>red.xPosition = whiteWidth + whiteAnchorLeft</code>). Here's the actual code of my evil creation:</p>
  
  <pre><code>var white = thisComp.layer("white");
  var whiteAnchorLeft = white.sourceRectAtTime(time-white.inPoint,true).left
  var whiteWidth = white.sourceRectAtTime(time-white.inPoint,true).width
  //[whiteAnchorLeft,whiteWidth]
  transform.xPosition = whiteWidth + whiteAnchorLeft 
  </code></pre>
  
  <p>This expression is inside of  <code>red &gt; transform &gt; x dimension</code>.</p>
  
  <p>When I try to make this work, I get 1920 as X and it doesn't move. What am I doing wrong?
  Thanks in advance!</p>
  
  <p>Note: <code>[whiteAnchorLeft,whiteWidth]</code> <em>is commented because After Effects is such an amazing software and it throws an error saying this "method is undefined" (???) althoug I've seen tutorials writing this down in the code.</em></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-06T12:02:19.833Z
Comments.Text: You forgot the `;`s. You need semicolons after all but your first line, that's where that error comes from.
Comments.UserDisplayName: stib
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-06T12:27:14.757Z
Comments.Text: Also, you don't explicitly use the property name on the left hand side to set it, you just return a value. Thus to set the position of a layer you don't do `transform.xPosition = someValue` you just put `someValue` as the last line of the expression  (apart from the fact that `transform.xPosition` isn't a thing, unless it's a variable that you've created).
Comments.UserDisplayName: stib
Tags: <after-effects><after-effects-expressions>
Title: Make a solid push another solid
UserDisplayName: spund3
ThreadText: # Make a solid push another solid
  
  (Asked by: username_0 on 2020-06-04)
  
  Here's the situation: I'm not new to After Effects. I've been using it for a while and I could say I'm an intermediate user. My knowledge is limited to everything but expressions.
  
  So, I have a **white** solid and a **red** solid. As the white solid increases width (scale), I want it to push the red solid. I'm not a newbie into programming, however, I'm either an advanced user. My guess on how to do it is the following one: get white's solid left and width properties from anchor point and add them to the X position of the red solid (`red.xPosition = whiteWidth + whiteAnchorLeft`). Here's the actual code of my evil creation:
  
  ```
  var white = thisComp.layer("white");
  var whiteAnchorLeft = white.sourceRectAtTime(time-white.inPoint,true).left
  var whiteWidth = white.sourceRectAtTime(time-white.inPoint,true).width
  //[whiteAnchorLeft,whiteWidth]
  transform.xPosition = whiteWidth + whiteAnchorLeft 
  
  ```
  
  This expression is inside of `red > transform > x dimension`.
  
  When I try to make this work, I get 1920 as X and it doesn't move. What am I doing wrong?
  Thanks in advance!
  
  Note: `[whiteAnchorLeft,whiteWidth]` *is commented because After Effects is such an amazing software and it throws an error saying this "method is undefined" (???) althoug I've seen tutorials writing this down in the code.*
  
  **Tags:** after-effects, after-effects-expressions
  
  > **Comments:**
  > **username_1**: You forgot the `;`s. You need semicolons after all but your first line, that's where that error comes from.  
  > **username_1**: Also, you don't explicitly use the property name on the left hand side to set it, you just return a value. Thus to set the position of a layer you don't do `transform.xPosition = someValue` you just put `someValue` as the last line of the expression  (apart from the fact that `transform.xPosition` isn't a thing, unless it's a variable that you've created).  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-06. Score: 1
  
  The `sourceRectAtTime(n)` method does what it says on the tin: returns the dimensions of the **source** of a layer, at **comp** time **n**. So because the source of your layer is 1920px wide, it returns 1920.
  
  You want to be using another method, the `toComp` layer space transform. It returns the comp co-ordinates of a point in layer co-ordinates. To find where the top right (in layer co-ordinates it will be [0,0]) of a layer is you'd do
  
  ```
  thisComp.layer("theLayerName").toComp([0,0]);
  
  ```
  
  To find where the anchor point of a layer is in comp co-ordinates:
  
  ```
  let theLayer = thisComp.layer("theLayerName");
  theLayer.toComp(theLayer.anchorPoint);
  
  ```
  
  The really useful thing about toComp is that it works regardless of the parent chains that the layer may be connected to, and any transformations that have been applied.
  
  To apply it to your case apply this to the red's position property:
  
  ```
  let white = thisComp.layer("white");
  let red = thisComp.layer("red");
  let sRect = white.sourceRectAtTime(time, true);
  let offset = white.toComp(sRect.width, sRect.top); //top right of the white layer
  value + offset; 
  
  ```
  
  `value` in the last line is a property that returns the currently set value of the layer property, after keyframes. So this will add the offset to whatever the position currently is.
  
  There is no need to use `time-white.inPoint` when calculating `sourceRectAtTime` because that method expects comp time as the first parameter, not layer time.
  
  
  ---
  
  