Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Source Text Expression: Looking to animate months (type, not numbers)

  • Source Text Expression: Looking to animate months (type, not numbers)

    Posted by Jonathan Lutjens on March 15, 2012 at 4:40 pm

    Hello,

    It’s been a little while since I’ve taken advantage of the community with a question. I’ve spent the last hour searching the web and these forums to find a solution and so far have come up empty.
    My apologies if I’ve overlooked a pre-existing post.

    I’m trying to find an expression that will allow me to have source text change from “Jan” all the way through “Dec.” I’ll then loop this as the numeric years count up. I’ve got the numeric year animation taken care of thanks to one of Mr. Ebbert’s expressions. Unfortunately, I’m not fluent enough in scripting to be able to alter that from the numbers changing to actual words.

    I’m sure this is an entry level problem, but it’s beyond me.

    Your help is much appreciated.

    Thank you,

    Jon

    Declan Smith replied 14 years, 2 months ago 3 Members · 6 Replies
  • 6 Replies
  • Dan Ebberts

    March 15, 2012 at 5:04 pm

    Here’s one way that maps the month number (1-12) to text:

    m = 7; // July
    monthText = “JanFebMarAprMayJunJulAugSepOctNovDec”;
    monthText.substr((m-1)*3,3)

    Dan

  • Jonathan Lutjens

    March 15, 2012 at 5:09 pm

    Thanks for the quick response, Dan.

    Would you have time to quickly explain that to me? I’d like to learn how it works if I can.

    Thanks!

    Jon

  • Jonathan Lutjens

    March 15, 2012 at 5:16 pm

    I responded a bit quickly to that last one.

    Apologies, I’m not able to discern how you would make the months cycle through (Jan-Feb-Mar) over time using the code you posted.

    Mas info?

    Thank you.

  • Jonathan Lutjens

    March 15, 2012 at 5:20 pm

    Aaaaand, too quick again.

    I just pickwhipped the value for m to a slider control. Bam!

    Thanks so much, Dan! Very elegant and cool.

    If you have the time, I would still like to see how this thing works. I’d love to learn more.

    Adios,

    Jon

  • Dan Ebberts

    March 15, 2012 at 5:26 pm

    The key is the JavaScript string operator substr(), which takes two parameters–the index of the first character (zero-based) and the number of characters. So with the string defined in monthText, you would get “Jul” with monthtText.substr((7-1)*3,3) which would be monthText.substr(18,3) (start at character 18 and extract 3 characters = “Jul”).

    Dan

  • Declan Smith

    March 19, 2012 at 2:40 pm

    An alternative for a self contained looping expression is as below, using an array. The animationLength is the time over which one complete cycle is to be completed, in this case 5 seconds.

    animationLength=5;
    months=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
    months[Math.floor(time*months.length/animationLength) % months.length]

    I have edited the script so you can adapt this for longer or shorter arrays.

    Declan Smith
    https://www.madpanic.tv
    After Effects CS5.5/ FCS3 / Canon 7D / Canon XL2 / Reason / Cubase

    “it’s either binary or it’s not”

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