ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expression with user-defined comp

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Noel Powell
Expression with user-defined comp
on Nov 5, 2019 at 5:14:26 am

I have a layer in "comp A", with many expressions that reference a layer in "comp B". I would like to give the user a simple method for making those expressions reference a layer in "comp C", "comp D", etc... or even possibly a comp that they create. I've been racking my brain, but can't think of any way to give them that option, without them editing each expression themselves. A simple "Comp Control", similar to the "Layer Control" expression control would do the trick, but that doesn't exist. And it appears that comps don't have an index, so an expression that references a comp by index won't work either. Does anyone have any ideas? Thanks in advance.

Creation Effects - Creative tools for After Effects: http://CreationEffects.com


Return to posts index

Andrei Popa
Re: Expression with user-defined comp
on Nov 5, 2019 at 7:16:55 am

I would create a text layer with the name of the comp I want to refer to.
Then write the reference for the composition like this: comp(textLayer.text.sourceText.value)
And put some conditions maybe, so if the composition with the value of the layer doesn't exist, some default values come in.

Andrei
My Envato portfolio.


Return to posts index

Tomas Bumbulevičius
Re: Expression with user-defined comp
on Nov 5, 2019 at 10:03:40 am

In addition to what Andrei suggested - you could reference comps by naming them [comp-1], [comp-2], [comp-x], and then getting index by:
thisComp.name.split("-")[1]

Find out more:
After Effects Tutorials: motion design, expressions, scripting.
Boxer - Dynamic Text Boxes Template with a Live Preview


Return to posts index


Noel Powell
Re: Expression with user-defined comp
on Nov 5, 2019 at 12:22:39 pm

Those are both creative solutions to my problem. I'd like to preserve the user's capability to name their comps whatever they want, but I think your idea, Andrei, will work nicely. They can easily rename the text layer to whatever the name of their comp is. Well done! Thanks!

Creation Effects - Creative tools for After Effects: http://CreationEffects.com


Return to posts index

Noel Powell
Re: Expression with user-defined comp
on Nov 5, 2019 at 2:56:39 pm

I hadn't used the sourceText function before, and I realize now that it gets the text written with the Text tool, not the text from the name of the layer, which is fine - the user will edit the text with Text tool. For anyone who needs it, here is what I did to get a value from a comp and layer that the user specifies...

After creating two text layers, one named "Target Comp Name", and one named "Target Layer Name", reference them like this...

targetComp = thisComp.layer("Target Comp Name").text.sourceText.value;
targetLayer = thisComp.layer("Target Layer Name").text.sourceText.value;
x = comp(targetComp).layer(targetLayer).transform.opacity

Creation Effects - Creative tools for After Effects: http://CreationEffects.com


Return to posts index

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