Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Measuring width of objects in precomp

  • Measuring width of objects in precomp

    Posted by Yan Trudel on June 19, 2017 at 3:57 pm

    Hi everyone,

    I dont post here often since a lot of times I find my answers on the forums from other people facing the same challenges. Thank all of you guys for all the knowledge you guys share everyday.

    I’m working on a project where I’m building a template for editors to use to put in the day and time at which shows play.
    That info then appears in 2 boxes that are side to side. Depending on the input text, the width of the combined boxes is always different.

    Here is what it looks like :

    My question : can After effects calculate the total width if they are inside a precomp and how could i go about doing that?

    Thanks in advance!

    Yan Trudel replied 9 years, 1 month ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 19, 2017 at 5:26 pm

    Hard to say exactly without knowing more detail, but probably something like this:

    r = comp(“your precomp name”).layer(“your layer name”).sourceRectAtTime(time,false);
    r.width

    sourceRectAtTime() is the key.

    Dan

  • Yan Trudel

    June 19, 2017 at 5:41 pm

    Thanks for the quick response Dan! By the way, you’ve been answering so many expressions questions I have had over the year so thanks for that too!

    I had actually tried sourceRectAtTime() but since the result of those 2 boxes is precomposed, it gives me the width of that composition.

    In my current build I use sourceRectAtTime() for each of the boxes with the text; one is right aligned and the other left aligned. They are in different compositions that are then juxtaposed. I’m actually trying to figure out the total length so I can always center the result of the combined width of the boxes since it can vary a lot :

    Although maybe my approach might be where I’m going wrong here?

  • Dan Ebberts

    June 19, 2017 at 5:47 pm

    I was assuming that you would use comp() to target the precomp so that you would have access to the layers inside.

    Dan

  • Yan Trudel

    June 19, 2017 at 5:52 pm

    Oh, rookie mistake!
    I’m going to try it out now!

  • Yan Trudel

    June 19, 2017 at 6:07 pm

    Thanks Dan!

    Since I’m not the expert, I sometimes forget I can reference directly into comps… Seems like it was rather simple but greatly appreciate the help! ☺

    I’ve used the expression you gave me to measure the total width like this :

    j = comp(“Precomp_JOUR”).layer(“boite_jour”).sourceRectAtTime(time,false);
    h = comp(“Precomp_HEURE”).layer(“boite_heure”).sourceRectAtTime(time,false);

    h.width+j.width;

    Now going to work on getting it to center automatically. Thanks again!

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