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

Is there a way to return an index value from a precomp or parent comp?

New Here ,
Nov 04, 2022 Nov 04, 2022

I've brainstormed a way to make my project easier to customize, but I don't know if it's possible.


I want to have one comp with multiple images in it. I want to make an expression for each layer's opacity so that it knows what it's index is in the parent comp. 

 

If this comp is in the parent comp at index 1, all images are 0 opacity except image 1, which is 100 opacity.

Repeat for all image layers.


Thanks!

TOPICS
Expressions
1.1K
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
Valorous Hero ,
Nov 04, 2022 Nov 04, 2022

Actually, the Parent Comp is the originating comp - this should be the way to describe the parent-child comp hierarchy. It will be awkward if the originating comp is the child. This is a common error among the majority of users. 

On your specific issue, I suggest you describe how the other layers/images will be displayed so that a clear solution can be provided for you - you've only described for a single layer/image. It will also be good if you are able to provide a screen capture of both the Parent and Child comps. 


Very Advanced After Effects Training | Adaptive & Responsive Toolkits | Intelligent Design Assets (IDAs) | MoGraph Design System DEV
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
LEGEND ,
Nov 04, 2022 Nov 04, 2022

Your idea makes no sense. Unless you duplicate the pre-comp a gazillion times in the project panel so it could function as a standalone unit, none of this would matter. The layers would simply turn off in every instance of the pre-comp, regardless. That's something you can't even avoid with essential graphics, as you're creating a causality loop. So whatever you have in mind would be best handled by tweaking the opacity of the actual duplicates in the parent comp, not the pre-comp.

 

Mylenium

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 ,
Nov 04, 2022 Nov 04, 2022

Returning the index of a nested comp is easy. If the comp name is Red Comp 1, this will do it:

I = comp("Parent Comp").layer("Red Comp 1").index;

 Put "I" in a property like Ellipse/Size or Opacity expression like this:

// Ellipse Size
I = comp("Parent Comp").layer("Red Comp 1").index;
if (I == 1)
	v = 400;
else if (I == 2)
	v = 300;
else if (I == 3)
	v = 200;
else if (I == 4)
	v = 100;
else
	v = 50;
[v, v]

//Opacity
I = comp("Parent Comp").layer("Red Comp 1").index;
if (I == 1)
	20;
else if (I == 2)
	40;
else if (I == 3)
	60;
else if (I == 4)
	80;
else
	100;

And you can get this:

RickGerard_0-1667582283931.gif

Is something like that what you are looking for?

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
New Here ,
Nov 04, 2022 Nov 04, 2022

Thanks for the reply! It's very helpful to know that I can reference other comps and layers within my project.

I've hit a snag, however. I'm hoping you can help me find a solution.

Within "Red Comp 1", I'll have 4 imaged, each one a different layer, but occupying the same position within the comp.

In the "Parent Comp", I hope to duplicate "Red Comp 1" four times (resulting in Red Comps 1-4 - perhaps it is noteworthy that each of those duplicates has a number matching it's index within the parent comp)

i = thisLayer.index;

p = comp("Parent Comp").layer(i).index;

if (p == i) {

 100;

} else {

 0;

}

 

But it would seem everything I try ends up a version of "3 = 3" or something, so when I go back to the Parent Comp, each version of Red Comp has full opacity on the top image (It'll always meet the check)

The part I'm struggling with is:

Can I turn

comp("Parent Comp).layer("Red Comp 1").index;

into something like 

comp("Parent Comp).layer(whatever layer this precomp is sitting on).index;

 

Is the fact that I'm duplicating Red Comp a problem? Can each copy of Red Comp do something slightly different depending on what layer it's on?

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
LEGEND ,
Nov 04, 2022 Nov 04, 2022
quote

Is the fact that I'm duplicating Red Comp a problem? Can each copy of Red Comp do something slightly different depending on what layer it's on?

 

No, it can't. I explained the why and how in my original reply, which everyone chose to ignore. You can't avoid creating four independent comps in the project window and substituting their usage, but then of course the whole song and dance with the expressions makes even less sense since you could just design the comps accordingly outright.

 

Mylenium

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
New Here ,
Nov 04, 2022 Nov 04, 2022

Do not assume I chose to ignore your original post. I did not get it's notification and simply missed it.

 

Now that I have read it, I am choosing to ignore it because it is very dismissive. Telling a learner their ideas make no sense isn't helpful. A simple no would do. An alternative idea that would make sense is ideal.

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
New Here ,
Nov 04, 2022 Nov 04, 2022

I figured out a simpler question to ask:

 

Is there a way, within the opacity property of a layer find out: "What is the index of the comp I'm in if I look up one layer of heirarchy?" 

If I could return that, I could make sure that the layer within the child comp that corresponds to that index is the only one visible. 

I would hope to reorder the layers in the child comp by dragging them around, rather than dragging around the comps within the parent comp because I have some indexing up there that I don't want to break.

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 ,
Nov 04, 2022 Nov 04, 2022
LATEST

To get the behavior you're after, you'd need to duplcate your comp in the project panel, not duplicate it as a layer in the parent comp. Then, assuming all the duplicates have unique names, you could do something like this:

comp("Parent Comp").layer(thisComp.name).index

 

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 ,
Nov 04, 2022 Nov 04, 2022

I'm not exactly sure what you are trying to do. You can use target == True to look for layer in and out points, but if your layers are all in the same position, then there is no way I can think of to decide which layer is visible by stacking them in the parent comp. 

 

If you have set layer in and out points, then an expression like this will turn on the visibility of the layer that is active:

L = comp("Parent Comp").layer(index);
if (L.active == true)
	100
else
	0

 

Any time the nested Child Comp layer in the main comp is active, it will be visible. You could combine a Linear or Ease method based on the layer in and out points to make the layers in the main comp fade in and out or even move them into position.

 

It would really help if I understood what you were trying to do. What is the design goal?

 

It would really help if I saw a screenshot of your Parent Comp with all modified properties revealed and a screenshot of the nested comp. Select the layers, press 'u' twice, take a screenshot, and drag it to the reply field. 

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