FORUMS: list search recent posts

How isolate numbers in Comp names and parse them into integers

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Xavier Bonet
How isolate numbers in Comp names and parse them into integers
on Mar 16, 2018 at 1:18:50 pm

In order to create a practical slide presentation template, I'm trying to get the name of each comp to be able to produce the number of the present slide within that same comp.

Each comp to which I refer is called "Slide x", x being 1, 2, 3, etc. Inside the comp there's an empty text layer where the slide number should appear. Now, I've gotten as far as obtaining the number by getting the name of the comp and then splitting it at the space, and holding the number value, which is after that space:

name = thisComp.name.split(" ")[1];
This works. But in order to make the design a little nicer, more slide-ier, I want to show the slide numbers as 001, 002, 003, etc., emulating the codes that old slides used to have. In order to do this, I'm trying to parse that number value as an integer so that I can use an if() statement that'll add "00" or "0" according to how many digits the number retrieved has (otherwise, it'll be something like 008, 009, 0010, 0011... which doesn't look good).
And here's where I'm hitting my head against a wall. I've looked all over, and even in the CCow forum all I can find is hot to parse from a text field into an integer, i.e. using parseInt(), which doesn't seem to work when the value in question is gotten from another source, in this case, the name of the comp itself... I've also tried other things and keep on getting "NaN" as a result.

So what am I doing wrong? How can I convert that number into an integer so that I can complete the expression I'm looking for?

Thanks in advance for any input you can give me!


Return to posts index

Xavier Bonet
Re: How isolate numbers in Comp names and parse them into integers
on Mar 16, 2018 at 1:32:03 pm
Last Edited By Xavier Bonet on Mar 16, 2018 at 1:38:19 pm

Ok... so right after posting this question I kept on trying by myself and finally found a way of solving the issue... So it now works, although I don't know WHY it works now and it didn't work before... I basically did the same thing but used different variable names. I must have made a small mistake somewhere and not have been able to find it out. Anyway, it now works and I didn't even have to parse anything. For what it's worth, this is what I have:

slideName = thisComp.name;
slideNumber = slideName.split(" ")[1];
if(slideNumber <10) "00"+ slideNumber else "0"+ slideNumber;


If anyone has a more practical way of working this out, I'd love to know about it. Cheers!


Return to posts index

Cassius Marques
Re: How isolate numbers in Comp names and parse them into integers
on Mar 16, 2018 at 5:11:11 pm

You're not having to parse because you're adding the string 00 (its between "") to another string. And It shouldn't work before for the same reasons, you were probably trying to add a string to an integer. In that case you should just have it display as 3 digits.
But since parsing 01 would still result in 1. The best way to display 001 is adding the string manually, like you have.

Cassius Marques
http://www.zapfilmes.com


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]