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

Scripting the values in the selected dropdown menu

Explorer ,
Jul 01, 2023 Jul 01, 2023

Sorry if this is basic, but I can't set the values of a currently selected dropdown menu based on an array described in a script.

 

I have been using a script that can create a new dropdown menu effect with the menu items I need to a layer named Control Centre:

 

thisComp=app.project.activeItem

var dropdownItems = 

[
"East Midlands",
"East of England",
"Greater London",
"North East of England",
"North West of England",
"South East of England",
"South West of England",
"West Midlands",
"Yorkshire and the Humber",
"(-",
"England",
"Northern Ireland",
"Scotland",
"Wales",
"UK"
];


theLayer = thisComp.layer("Control Centre");
dropdownEffect = theLayer.property("ADBE Effect Parade").addProperty("ADBE Dropdown Control");
dropdownEffect.property(1).setPropertyParameters(dropdownItems);

 

The name of the new expressionscript menu effect that it creates is Dropdown Menu Control.

 

Because I have many dropdown menus in my current project with tens and sometimes hundreds of items, I would like to modify this script so that it changes the menu options of the currently selected named dropdown menu. Because I have other expressions which refer to specifically named dropdown menus.

 

I tried to parse the currently selected item to set the array using .isDropdownEffect, but although I have the effect selected when I run the following script, nothing happens:

 

var dropdownItems = 

[
"Alex4D",
"East of England",
"Greater London",
"North East of England",
"North West of England",
"South East of England",
"South West of England",
"West Midlands",
"Yorkshire and the Humber",
"(-",
"England",
"Northern Ireland",
"Scotland",
"Wales",
"UK"
];

var props = app.project.activeItem.selectedProperties;
for (i=0; i<props.length; i++)
     {
      if (props[i].isDropdownEffect)
           {
            props[i].setPropertyParameters(dropdownItems)
            }
     }

 

 

Also, I would like to use prompt to enter the values as a comma-delimted string, but I can't paste values into the prompt field. How do I make it possible to use paste into a field in a prompt?

thisComp=app.project.activeItem

var theInput = prompt("Enter your , seprated array",0)

dropdownItems = theInput.split(",")

theLayer = thisComp.layer("Control Centre");
dropdownEffect = theLayer.property("ADBE Effect Parade").addProperty("ADBE Dropdown Control");
dropdownEffect.property(1).setPropertyParameters(dropdownItems);	

 

Help will be recieved gratefully!

 

Alex4D

TOPICS
How to , Scripting
1.7K
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

correct answers 1 Correct answer

Enthusiast , Jul 01, 2023 Jul 01, 2023

Both sets of code do seem to work, but with some caveats. It may depend on if you were selecting the Dropdown Menu Control effect or the actual Menu property, because selecting just the effect won't work with your code, as you would need to identify or loop through the properties in the effect to find the actual Menu property (it's actually property(1) of the menu effect). Also, on Mac at least you can paste into a prompt by right-clicking and selecting Paste there.

 

I'm also getting a scripting

...
Translate
LEGEND ,
Jul 01, 2023 Jul 01, 2023

You will likely have to re-design this with text fields and multiple dropdowns, then toggle visibilities. Dropdowns get sort of locked once they are populated and changing them after the fact is basically not possible.

 

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
Explorer ,
Jul 02, 2023 Jul 02, 2023

Thanks for answering on a Saturday.

 

So .setPropertyParameters can set the values of a dropdown control, but can only do it when the control is created?

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
Enthusiast ,
Jul 01, 2023 Jul 01, 2023

Both sets of code do seem to work, but with some caveats. It may depend on if you were selecting the Dropdown Menu Control effect or the actual Menu property, because selecting just the effect won't work with your code, as you would need to identify or loop through the properties in the effect to find the actual Menu property (it's actually property(1) of the menu effect). Also, on Mac at least you can paste into a prompt by right-clicking and selecting Paste there.

 

I'm also getting a scripting error if trying to do it onto a selected effect so that could even be causing your code to fail abruptly, and without warning if you're not using any kind of debugger:

"After Effects error: internal verification failure, sorry! {stream at index matchName="Pseudo/@@VZ4L33hTQ+C834jJeOfA5w" (mismatch with resultP, expected "Pseudo/@@i5MOg14MRDOoK5K/CfQpaw")}"

 

In the following code I first check if it's a dropdowneffect, and if not I check if it contains multiple properties (i.e. it is the main effect property) and if so check if property(1) of that property is a dropdowneffect. I also wrap setting the dropdown in a try/catch to avoid the error this returns from killing the script. I think in practice, even if you did actually have the 'Menu' property selected, the 'Dropdown Menu Control' effect will always come before it in any selection so it will be the 'else if' bit that always runs first.

 

And a side effect of setting the dropdown is that it seems to invalidate everything in selectedProperties, so if you wanted to loop through multiple selections at the same time you'd need to make a note of that selection in some other way at the start so you didn't later need to rely on selectedProperties.

 

 

var dropdownItems = 

[
"Alex4D",
"East of England",
"Greater London",
"North East of England",
"North West of England",
"South East of England",
"South West of England",
"West Midlands",
"Yorkshire and the Humber",
"(-",
"England",
"Northern Ireland",
"Scotland",
"Wales",
"UK"
];

var i, j, dropProp;
var props = app.project.activeItem.selectedProperties;
for (i=0; i<props.length; i++) {
	dropProp = null;

	if (isValid(props[i])) {

		alert("props["+ i + "] isValid");

		if (props[i].isDropdownEffect) {
			alert("actual menu prop was selected. matchname = " + props[i].matchName);
			dropProp = props[i];
		} else if (props[i].numProperties > 0 && props[i].property(1).isDropdownEffect) {
			alert("drop down menu effect was selected. matchname = " + props[i].property(1).matchName);
			dropProp = props[i].property(1);
		}

		if (dropProp != null) {

			alert("dropProp is valid = " + isValid(dropProp) + ". setting menu items");

			try {
				dropProp.setPropertyParameters(dropdownItems);
			} catch(e) {
				alert("error= " + e.toString());
			}

			alert("dropProp is valid = " + isValid(dropProp));
		}
	} else alert("props[" + i + "] no longer valid");

}

 

 

Just saw Mylenium's reply. It might be he's thinking about actual scripting UI dropdowns as he mentioned visibility which is more of a scriptUI thing. I've never tried scripting on these new Dropdown Menu Control effects before but they definitely appear to be changeable, although there is this annoying scripting error that I have no idea why it's happening. Just another of the many scripting bugs in AE I guess. 

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
Explorer ,
Jul 02, 2023 Jul 02, 2023

Thanks for putting in the work to investigate the limitations of this part of AE scripting.

 

I appreciate it.

 

Should I formally request that AE can reliably change the values of an already established dropdown control?

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
Enthusiast ,
Jul 02, 2023 Jul 02, 2023

Probably a good idea to report that bug to Adobe, assuming you're getting the same error when running that code? But it does appear to reliably change it, just need to manage that scripting error so it doesn't halt your script.

 

It doesn't appear to happen when running your 'add new effect' code, but I think it does happen on a fresh effect that hasn't previously been altered. Maybe because it's selected? I'd need to do more testing.

 

A decent amount of my scripting development time is spent working around AE scripting bugs that never get fixed, so generally I wouldn't let something like this stop me!

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
Enthusiast ,
Jul 07, 2023 Jul 07, 2023
LATEST

Just following up on this as I've now explored it further and submitting a bug report. Note: All the below code expects that you've created a layer with a Dropdown Menu Control, then have that effect (not the menu property) selected. The actual menu is the property(1) of the Dropdown Menu Control effect.

 

While accessing it through selectedProperties in this way does cause that error (which you can handle with a try/catch):

var dropdownItems = ["test", "drop"];
app.project.activeItem.selectedProperties[0].property(1).setPropertyParameters(dropdownItems);

 If you were to instead derive the layer and effect index from the selectedProperties and then access it from there, you don't get an error.

var dropdownItems = ["test", "drop"];
var theProp = app.project.activeItem.selectedProperties[0];
var theLayer = theProp.propertyGroup(theProp.propertyDepth);
var effectIndex = theProp.propertyIndex;
theLayer.property("ADBE Effect Parade").property(effectIndex).property(1).setPropertyParameters(dropdownItems);

All very weird. Still, I would probably just wrap the first solution in a try/catch anyway for simplicity. But it shows there's nothing really wrong with the setPropertyParameters method other than how it interacts specifically with the selectedProperties attribute.

 

 

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