• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Use part of the name of a comp in expression

New Here ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

Hello there,

I want to use part of the name of a comp to automate the actualization of expressions when duplicate this comps and the precomps in them. I labeled them as name_twodigitnumber, so I was wondering if there is some way to use Comp.name or a similar expression to get just the ending two digits number of the name of the comp as output, so they can actualize automatically when I make some duplicates. Hope the explanation is good enough.

Thanks in advance.

Diego.

TOPICS
Scripting

Views

1.8K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 16, 2016 Dec 16, 2016

Something like this would give you the number:

parseInt(thisComp.name.split("_")[1],10);

Dan

Votes

Translate

Translate
Community Expert ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

Something like this would give you the number:

parseInt(thisComp.name.split("_")[1],10);

Dan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 16, 2016 Dec 16, 2016

Copy link to clipboard

Copied

Thank you Dan. That seem to do the trick. Nonetheless doing several tests I came up with something like this below, as long as I still do not get how parseInt work exactly, and I prefer to go slow or workaround in order to understand what im using.

I want to get an "N" output referring another composition called "Holder_XX", where XX is a number with two digits, so I used this:

N=comp(("Holder_")+thisComp.name.split("_")[1]);

In order to increase automatically the "XX" (two digits number) by the name of the composition where im writing the script (name_yy).

Best regards, Diego.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

This was very useful, but it sent me down an internet hole trying to figure out what the ",10" was doing in the parseInt function.

I discovered that it designates the numeric system as base-10 (i.e. decimal). Apparently, if you leave that out of the expression, base-10 is automatically assumed. Why did you add it here?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2022 May 25, 2022

Copy link to clipboard

Copied

LATEST

Force of habit, mostly, but try parseInt(016) and see what you get. If you have an integer that starts with "0", for some strange reason, JavaScript will first try to interpret it as octal. So I include the ",10" just to be safe.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines