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

Change Expression based on Composition Name

Community Beginner ,
Jan 22, 2025 Jan 22, 2025

What I'm trying to accomplish is to have a specific number in an expression change based off a number in the composition name.

 

I have a character rig composition which needs to be used in several seperate compositions (Scenes). I have attached the rig controls to expression controls in a seperate Scene. However, in order to animate the character in each seperate Scene, I need to dedicate a character rig composition for each scene. For Example, Character Rig_Scene 1 is used in Scene 1, Character Rig_Scene 2 is used in Scene 2, etc.

 

Each time I duplicate my Character Rig_Scene #, I'd like the number to automatically change in the comp("Scene #") part of the expression. So comp("Scene 4") will pull the number from "Character Rig_Scene 4" composition.

 

Can this be accomplished? If so, what's a good approach?

 

Thanks for your help.

 

Please see photo for more context.

Expression Question.png

 

TOPICS
Expressions
731
Translate
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 , Jan 22, 2025 Jan 22, 2025

I think something like this should work:

comp("Scene " + thisComp.name.split(" ").pop()).layer("Taylor Animation Control").effect("L Arm")("Angle")
Translate
Community Expert ,
Jan 22, 2025 Jan 22, 2025

I think something like this should work:

comp("Scene " + thisComp.name.split(" ").pop()).layer("Taylor Animation Control").effect("L Arm")("Angle")
Translate
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 Beginner ,
Jan 22, 2025 Jan 22, 2025

Golly! That worked, thank you very much.

 

So how is this expression working now? Like how does it know to read the Scene #?

Translate
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 ,
Jan 22, 2025 Jan 22, 2025

It takes the name of the comp with the expression, splits that into an array of chunks wherever there's a space in the name, and then takes the last chunk (which is "4" in your example) and appends that to "Scene ".

Translate
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 Beginner ,
Jan 22, 2025 Jan 22, 2025

Okay, I think I'm understanding. So the .pop() is how you are telling it to only see the last part – so the "4"?

Translate
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 ,
Jan 22, 2025 Jan 22, 2025

Yes. 

thisComp.name.split(" ")

Gives you this array:

["Taylor", "2.0_Scene", "4"]

and the .pop() gives you the last element of the array.

 

Translate
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 Beginner ,
Jan 23, 2025 Jan 23, 2025
LATEST

Incredible. Expressions rule!

 

Thank you much for your help and explanation on this.

Translate
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