Skip to main content
Participating Frequently
Jan 22, 2025 4:36 PM UTC
Answered

Change Expression based on Composition Name

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.

 

Dan Ebberts
Dan EbbertsCorrect answer
Community Expert
Jan 22, 2025 10:25 PM UTC

I think something like this should work:

comp("Scene " + thisComp.name.split(" ").pop()).layer("Taylor Animation Control").effect("L Arm")("Angle")

6 replies

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
Jan 22, 2025 10:25 PM UTC

I think something like this should work:

comp("Scene " + thisComp.name.split(" ").pop()).layer("Taylor Animation Control").effect("L Arm")("Angle")
Translate
Participating Frequently
Jan 22, 2025 10:40 PM UTC

Golly! That worked, thank you very much.

 

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

Translate
Dan Ebberts
Community Expert
Community Expert
Jan 22, 2025 10:47 PM UTC

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