Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Use Comp Name as layer index value?

  • Use Comp Name as layer index value?

    Posted by Anders Hattne on June 8, 2012 at 12:07 pm

    Hi,
    I’m planning on duplicating a bunch of comps. First comp is called “1”. When duplicating next one will be 2 and so on.
    I was hoping to use these comp names as values in order to retrive data from layers in another comp. So the comp “2” would refer to layer 2 in this other comp.
    I tried this:
    cubeNumber=thisComp.name;

    src=comp(“valores-colores”).layer(cubeNumber);

    Which doesn’t work since cubeNumber is a name and not a value.

    Is there a way of turning the comp.name into a value?

    There’s a hundred layers so I was hoping to avoid changing all duplicated comps ….

    http://www.ardillamedia.com

    Anders Hattne replied 14 years, 2 months ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    June 8, 2012 at 3:42 pm

    Try this:

    cubeNumber = parseInt(thisComp.name.split(” “)[1],10);
    src=comp(“valores-colores”).layer(cubeNumber);

    Dan

  • Anders Hattne

    June 8, 2012 at 3:43 pm

    Seems like I may have gotten it:

    myInteger = parseInt(myString);

    Didn’t know about the parsing term and find it generally a bit tricky to find information on these things.

    is this Javascript? And do most javascrips ..functions work in AFX?

    http://www.ardillamedia.com

  • Anders Hattne

    June 8, 2012 at 3:45 pm

    Oh thanks! Seems as you replied justa as I found the information..

    In the end the comp names when duplicating have turned out to be “0 50, 0 51, 0 52, 0 53….” But I guess I can find my way around splitting it up and only using the last 2 digits.

    http://www.ardillamedia.com

  • Dan Ebberts

    June 8, 2012 at 3:48 pm

    >is this Javascript?

    Yes it is.

    >And do most javascrips ..functions work in AFX?

    Pretty much all the core stuff–everything except the stuff used specifically for web pages.

    Dan

  • Anders Hattne

    June 11, 2012 at 11:28 am

    Final expression that I used:
    First comp was named cubo 01.. then duplicated

    nombre=” “+thisComp.name;
    nombre1=nombre.substr(5);
    layerNo = parseInt(nombre1);
    src=comp(“valores-colores”).layer(layerNo );

    works like a charm!

    http://www.ardillamedia.com

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