Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Can an expression acknowledge the Comp’s name?

  • Can an expression acknowledge the Comp’s name?

    Posted by Bert Brown on November 13, 2008 at 5:22 pm

    I have to create many variations of a comp. There is a specific labeling system I have to use and I’m wondering if I can set up a if-then situation to adjust parameters based on what I name the comp.

    so for example i have a comp name:

    PRIMEHD_P2_L2_TSS

    and I want the expression to look for the number after that “L” and adjust a slider number (BAR LENGTH SLIDER) to match that digit. in this case “2”

    possible? i ask because i know very little about how to format a label to be read, especially pin-pointing a specific position in that label.

    thanks

    ———————————-

    peep my over-the-interweb band, red abbott.
    “we electro-rock over long distances…”

    Lloyd Alvarez replied 17 years, 5 months ago 4 Members · 8 Replies
  • 8 Replies
  • Darby Edelen

    November 13, 2008 at 5:46 pm

    [Bert Brown] “so for example i have a comp name:

    PRIMEHD_P2_L2_TSS

    and I want the expression to look for the number after that “L” and adjust a slider number (BAR LENGTH SLIDER) to match that digit. in this case “2””

    I think this should get you most of the way there:


    n = thisComp.name;
    a = n.split("_");

    a will be an array with the following values:


    a[0] = PRIMEHD
    a[1] = P2
    a[2] = L2
    a[3] = TSS

    So to get the digit in a[2] you could use:

    dig = a[2].charAt(1) * 1; //multiply by one to convert character to an integer

    I haven’t tested this but I believe it should work.

    Darby Edelen

  • Bert Brown

    November 13, 2008 at 6:12 pm

    radical. works great. thanks so much

    this is also really helpful for just understanding the way expressions can use text. i had never utilized split or charAt

    if i wanted an expression to look at a character, like the “L” how would i do that? just not multiply by 1?

    ———————————-

    peep my over-the-interweb band, red abbott.
    “we electro-rock over long distances…”

  • Dan Ebberts

    November 13, 2008 at 6:16 pm

    Another way:

    n = thisComp.name;
    parseInt(n[n.indexOf(“_L”) + 2],10)

    Dan

  • Lloyd Alvarez

    November 14, 2008 at 5:39 am
    c=thisComp.name
    c.charAt(c.lastIndexOf("_")-1)

    Since we’re doing remixes, here’s my take on it 😉

    -Lloyd

    https://aescripts.com

  • Lloyd Alvarez

    November 14, 2008 at 5:49 am

    forgot that it needed to be used as a number:

    c=thisComp.name
    parseInt(c.charAt(c.lastIndexOf(“_”)-1),10)

    BTW, just recently learned about the various flavors of parseInt so if you are following along at home, make sure to add the ,10 whenever you use parseInt to make sure you pull base 10 numbers which I imagine is what you’ll want 99% of the time..

    -Lloyd

    https://aescripts.com

  • Darby Edelen

    November 16, 2008 at 11:53 pm

    In a case where there is not a need to convert from an arbitrary base to decimal, wouldn’t multiplying or dividing by 1 be easier to implement? And also decrease the chances of accidentally misinterpreting the string as octal?

    Darby Edelen

  • Dan Ebberts

    November 17, 2008 at 7:14 pm

    Good point. In a case like this it would make sense to take advantage of JavaScript’s implict type conversions. I think I’d use 0 + though. Just like you can convert a number to a string like this:

    n = 1234.567;
    “” + n;

    You could go the other way like this:

    str = “1234.567”;
    0 + str;

    Dan

  • Lloyd Alvarez

    November 21, 2008 at 7:47 pm

    I love the fact that I am always learning new things from you guys. 🙂

    -Lloyd

    https://aescripts.com

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