Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions finding layers in another comp and extracting values…

  • finding layers in another comp and extracting values…

    Posted by Pete Menich on February 14, 2022 at 2:43 pm

    I have a comp with Country names as text layers, in the correct x & y positions to match a mercator projection. Lets call this ‘CompNames’

    I have another comp with each country as a text layer with there land area is part of the name. So for example; Russia,66000 or Germany,5643. Let’s call this ‘CompAreas’

    What I want to do is add an expression to the scale property of the name layers in CompNames, that looks for the corresponding layer in CompAreas – (by finding the first part of the layers name string before the comma), and then uses the second part of the name string after the comma to extract the value to be used in a range mapping function.

    That way I can set the scale of the names depending on the land area of the corresponding country.

    So for instance, the name Russia will be big and the name ‘Portugal’ will be smaller.

    Does that make sense?!

    I have no idea if this is even possible.🤓

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

    February 14, 2022 at 8:37 pm

    Should be do-able. It might look something like this:

    c = comp("CompAreas");

    maxArea = 99999; // whatever the area is for the largest country

    str = "";

    for (i = 1; i <= c.numLayers; i++){

    if (! (c.layer(i).name.indexOf(name) == 0)) continue;

    str = c.layer(i).name;

    break;

    }

    if (str != ""){

    area = parseInt(str.split(",")[1],10);

    value*(area/maxArea);

    }else

    value

    You’d probably want to add more error checking if other people will be using it (like making sure the layer name in CompAreas actually has a comma in it instead of just assuming it does).

  • Pete Menich

    February 15, 2022 at 12:01 pm

    Hey Dan – long time no brain pick! Thanks for looking at this.

    It didn’t work for me I’m afraid & not I’m sure I understand why.

    I’ve attached a reduced version to help illustrate it better…

    In ‘CompNames’ I have a single text layer that I’ve named ‘Russia’.

    I need the code to ‘look into’ CompAreas and find the layer that starts with ‘Russia’.

    (Russia,6600000,6600)

    I then need it to return the value after the fist comma (6600000) which, I will then use in a RangeMapper function to drive the scale. (I can try and work this bit out).

    So, if I change the text to say ‘Canada’, it will find the layer starting with Canada (Canada,3800000,3800) and return 3800000.

    FYI: (the second value after the last comma is just the first value/1000, because sometimes AE freaks out with numbers over 32K)

    Once I have this working, I can then paste it to all the country names in my comp & (hopefully) I can get them to scale relative to land area.

    P

  • Dan Ebberts

    February 15, 2022 at 2:15 pm

    I think the reason it doesn’t work is that you have it applied to a text layer’s source text property and this line:

    value*(area/maxArea);

    is expecting that the expression’s property is scale. If you comment that line out you’ll see it comes up with 6600 for area. Not sure where you want to go with it from there.

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