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

Array of all comp layers into items of a Dropdown menu expression

Community Beginner ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Hello!

I encountered at first glance a simple task in one of the projects.
I have a small comp with icons (100 x 100 pixels), it has a bunch of layers with different icons.
This composition is in another composition and has the DropDown Menu Controller effect applied to it.
How can I make the items in this controller take an array of layers from inside this composition with names and, depending on the selected item, show only selected icon?

I don't know expression language very well and tried the help of ChatGPT but the results don't work.

 

ChatGPT provided me this solution for the list of layers:

names = [];
for (i = 1; i <= thisComp.numLayers; i++) {
    if (i != index) {
        names.push(thisComp.layer(i).name);
    }
}
names;

But there's an error in line 1 (coldn't turn result into numeric value)

TOPICS
Expressions , Scripting

Views

724

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 , Mar 04, 2023 Mar 04, 2023

Add a Menu Control to the Icons layer (nested comp - your pre-comp).

 

Add this expression to the opacity for each icon layer in the Icons comp:

 

ctrl = comp("Main").layer("Icons").effect("Dropdown Menu Control")("Menu");
if (ctrl == index)
	100
else
	0

 

Unfortunately, you cannot tie a layer name to a menu because there is no way to keyframe the Expression Controls/Dropdown Menu Control/Edit property.

 

You may be able to write a script that looks at all of the layers and pulls layer names fro

...

Votes

Translate

Translate
Community Beginner ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Here is the illustration what i mean:
2023-03-04_14-46-53.png2023-03-04_14-46-21.png

Votes

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 ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

And one more small addition: I need the dropdown menu list to take the names of the layers itself and not set them manually through the Edit menu for two reasons:
1) a lot of icons
2) I plan to add new icons inside the composition and I don’t want to manually add new positions to the dropdown list every time, I need it to understand how many layers are inside the composition and update their names and number

Votes

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 ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Add a Menu Control to the Icons layer (nested comp - your pre-comp).

 

Add this expression to the opacity for each icon layer in the Icons comp:

 

ctrl = comp("Main").layer("Icons").effect("Dropdown Menu Control")("Menu");
if (ctrl == index)
	100
else
	0

 

Unfortunately, you cannot tie a layer name to a menu because there is no way to keyframe the Expression Controls/Dropdown Menu Control/Edit property.

 

You may be able to write a script that looks at all of the layers and pulls layer names from them, but there is no way for an expression to control a property that cannot be animated. 

Votes

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 ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Rick, thanks for the reply and clarification!

I correctly understood that through expressions I can only manually create items for the dropdown menu?

I also noticed that if a composition with icons is used several times in the main composition (for example, you need several icons), then the icons will change immediately in all precomps (because they refer to same reference).

 

I correctly guess that this task can be solved through time remapping referring to a frame inside the composition? Make all the icons 1 frame long and place them in a sequence and then refer to the frame with the desired icon by the item from the dropdown menu. All animation will occur outside the composition, just the scale change.

 

I i guessed correct - how can i do it?

Votes

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 ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

If you tie all of the layers in a nested comp to a single controller, that controller controls every icon in the nested comp.

 

If you sequence the layers in a nested comp with each layer 1 frame long, then you can apply time remapping to the nested comp and set up an expression with an expression control slider or a dropdown menu to choose a specific frame for Time Remapping. 

 

You still have the layer naming problem in a dropdown menu. 

 

If you put the Dropdown Menu Controller on the time remapped layer, expression for time remapping a sequenced nested comp would be:

c = effect("Dropdown Menu Control")("Menu")

You could save that as an animation preset and apply it to every copy of your nested comp in the main comp. 

 

Votes

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 ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Thanks Rick, this solution works!

Right now I'm using this quick solution, but in the future I'll try to make a script that would create the items I need with the right names inside of dropdown menu.

I found something similar in the adobe help script guide:

 

Dropdowneffect = Dropdowneffect.setPropertyParameters(["Monday", "Wednesday", "Friday", "Sunday"]);

 

Votes

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
LEGEND ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Create a dummy layer in the pre-comp with the self-populating "Layer" expression control link it to a slider in the parent comp to address the index.

 

Mylenium

Votes

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 ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

LATEST

Did you mean layer control effect?

It really gives a list of the names of all the layers that I need, but apparently it is impossible to set keys on it, I could not pick whip it with either the same Layer control in the parent composition, or with the slider controller. Is it even possible to do this?

Votes

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