Call image in pre composition by name with expression

Community Beginner ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Hi,

 

I have in my projects for example 3 images:

- a.jpg

- b.jpg

- c.jpg

I have a pre composition named "My_images" which contains: a.jpg, b.jpg and c.jpg

Is it possible with expression to call if i want: a.jpg OR  b.jpg OR c.jpg.

 

Thank you in advance.

 

Cordially

 

Claire

TOPICS
Scripting

Views

132

Likes

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 , Jun 09, 2022 Jun 09, 2022

Screenshot 2022-06-09 at 09.43.58.png

Here I have a precomp with three solid layers. A slider in the precomp controls the opacity of all of them. The slider has been added as Essential Property, such that it shows up as a control on the precomp layers in the main comp. There I set the slider value to three different values, in order to get three different variants how the precomp is looking.
You can download the aep file here:
https://www.dropbox.com/s/84v6insg4jzw674/choose_layer_in_precomp_with_slider.aep?dl=0

Likes

Translate

Translate
Community Expert ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

I'm not sure what you're asking, but if you do something like this:

myLayer = null;
try{
  myLayer = comp("My_images").layer("a.jpg");
}catch(e){
  try{
    myLayer = comp("My_images").layer("b.jpg");
  }catch(e){
    try{
      myLayer = comp("My_images").layer("c.jpg");
    }catch(e){
    }
  }
}

at the end, myLayer will be a.jpg, b.jpg, c.jpg, or null (if a, b, and c don't exist). Does that help?

Likes

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 Beginner ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Thank you for your answer first.

Sorry i will be more explicit.

This is what i want, i add in my composition two times the pre composition "my images".

1) First time i use "my_images": i want to hide a.jpg and c.jpg for example and also keep only b.jpg

2) Second time i use "my_images:i want to hide a.jpg and b.jpg for example and also keep only c.jpg

 

To ask this question in a general way, how to change values of layers (opacity, scale) from a precomposition containing several layers (images for example). My goal is to use the same precomposition that contains a lot of images multiple times and only using expression to select what image(s) i want to see in my composition.

 

Thank you in advance.

Likes

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Ah, OK. I think the only way you could do something like that would be to set your precomp up so that each image is visible for a specific amount of time ( 1 frame, 1 second, etc.) and then time remap each precomp layer instance and set the time remapping time corresponding to the image you want active. You can't do it directly, the way you're suggesting, because you can't have differenet layer instances of the same precomp render differently (the precomp only renders once).

Likes

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

What you want is not possible. A pre-composition is always just an instance of the same comp and responds to the same changes globally. Even all Essential Graphics/ Master property trickery doesn't change that. You have to use a different workflow like staggering the images and accessing them via time-tremapping, which then could be rigged with a valueAtTime() expression or even a simple slider. Similarly, you can use all sorts of effects to "unhide" layers by rendering them inside the effect while it's otherwise invisible by referencing the effect in one of the effect's input dropdowns. This then again could be controlled with expressions. Either way, your original idea will never work and even in the scenarios I laid out you can't avoid duplicating the pre-comp at least occasionally.

 

Mylenium

Likes

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

Would it work to have

- a slider control effect inside the precomp

- expressions on layers A, B, and C's opacity which turn exactly one of them to 100%, depending on if the slider has value 1,2, or 3.
- make the slider a essential property.
Now you can choose with the essential property in each precomp layer main comp, which image you want to use.

Likes

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 ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

It doesn't seem like that will work. There's still only one slider and one precomp, right?

Likes

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 ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

There would be one slider inside a single precomp. And in the main comp on each precomp layer, which is an instance of that precomp, there would be a copy of that slider (essential property), which overwrites the behavior of it independently for each instance.

Likes

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 ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

>on each precomp layer, which is an instance of that precomp, there would be a copy of that slider

How would you do that? Admittedly, my knowledge of essential graphics is pretty limited, and I'd love to see it if you could throw together a simple project that demonstrates this.

Likes

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 ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

Screenshot 2022-06-09 at 09.43.58.png

Here I have a precomp with three solid layers. A slider in the precomp controls the opacity of all of them. The slider has been added as Essential Property, such that it shows up as a control on the precomp layers in the main comp. There I set the slider value to three different values, in order to get three different variants how the precomp is looking.
You can download the aep file here:
https://www.dropbox.com/s/84v6insg4jzw674/choose_layer_in_precomp_with_slider.aep?dl=0

Likes

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 Beginner ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

Hello everyone,

 

First of all, thank you for your help and valuable comments.


Mathias Möhl's answer works perfectly.
I use the slider with a value for each layer in "precomp".
Example:
- 1 for red
- 2 for blue
- 3 for green
As I have a problem with a lot of images and it will be tedious to know if I should put the slider on 54 or 87 for example here is what I did.
1) I use hidden text
2) I enter "Red" for example
3) I am looking for the input layer number, here "Red"
4) I apply the layer number to the slider
5) Display of solid "Red"
In this way I no longer "play" with the slider but only with one or more text layers that I hide (opacity at 0).
I don't know if it's clear so that it can be used by others if needed.

 

Thank you all, problem solved 😉

Likes

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 ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

LATEST

Thanks Mathias--I learned something! I should have paid more attention when the Essential Graphics feature was added.

Likes

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