Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions toComp… I just don’t get it

  • toComp… I just don’t get it

    Posted by Jeff Hinkle on August 20, 2021 at 7:57 pm

    Working on a project and once again needed to get the coordinates of a specific edge. After a lot of trial and error, experimentation, and copying code from much smarter people’s examples online I finally got things to work with toComp but damned if I fully understand why. I certainly couldn’t explain it or do it again

    I get the basic concept of toComp, but no matter how much I read or how many videos I watch, I just can’t get the nuts and bolts to sink into my brain. So if it’s a.toComp([0,0,0]) I get that [0,0,0] is the top-left corner of the comp, but to what end? Do you always use that? What if the layer isn’t comp sized? What is being converted into what? What goes in, what comes out?

    I sorta get the what but not at all the how. Hopefully if I can finally get this to sink in, fromComp will also make sense. So can anyone explain toComp in a way that I might finally get it? I realize that’s a tough ask if you don’t know what part I’m not getting, but at this point any explanation will be more knowledge than I currently have.

    Dan Ebberts replied 4 years, 8 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    August 20, 2021 at 10:28 pm

    >So if it’s a.toComp([0,0,0]) I get that [0,0,0] is the top-left corner of the comp

    No, a.toComp([0,0,0]) would translate layer a’s upper left corner (usually) into comp coordinates. It’s useful if you want to position another layer (let’s say layer b) over a specific point on layer a for which you have the coordinates in layer a’s coordinate system. So the Position expression to put layer b on layer a’s upper left corner would be:

    a = thisComp.layer("a");

    a.toComp([0,0,0])

    To put layer b over layer a’s anchor point:

    a = thisComp.layer("a");

    a.toComp(a.anchorPoint)

    To put layer b over the Bulge Center of layer a’s Bulge effect:

    a = thisComp.layer("a");

    a.toComp(a.effect("Bulge")("Bulge Center"))

    The thing that these three examples have in common is that the parameter provided to toComp() is always a point relative to layer a’s upper left corner and the result is always in the comp’s coordinate system. Note that you need the a. prefix of a.toComp to tell the expression engine that you’re providing a point in layer a’s coordinate system. If you leave that out, it will assume you’re referring the layer space of the layer with the expression (layer b in these examples), which would probably not be useful. Hope that helps.

  • Jeff Hinkle

    August 23, 2021 at 1:47 pm

    Amazing! After reading your explanation and examples, I can now consistently put Layer b pretty much where I want on Layer a. More importantly, I think I now understand the syntax enough to make it work on more complex future projects (and probably sort out fromComp and toWorld). Thank you so much for finally sinking this into my brain!

    If you ever publish an After effects book, I’ll preorder 3 copies and hand out the extras to coworkers.

  • David Avila

    August 24, 2021 at 7:22 pm

    I hope it’s not rude to tack on a question concerning the toComp function:

    I’ve noticed that it requires two points. So when you want to use just one (x or y) point, you have to evaluate both, then pick one using the array syntax, right?

  • Dan Ebberts

    August 24, 2021 at 8:30 pm

    toComp() takes a single point as its main parameter (with time as an optional, second paramter). The point can be either 2D (x and y) or 3D (x,y, and z) in array notation. If you’re only interested in one dimension of the result, then you would extract that from the result using [0] or [1] (or sometimes [2], which is usually ignored from toComp). I don’t know if that answers your question.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy