ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

set a function to call up a certain code based on a user dropdown choice

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
David Clabaugh
set a function to call up a certain code based on a user dropdown choice
on Apr 3, 2018 at 1:00:09 am

HI,

I am building a tool that will apply a set of effects to the selected layer. The effects parameters will change based on a drop-down UI element chosen by the user. What is the best way to implement the function? Currently, I am using an if/else if to call different settings to be applied to each layer, but that isn't working.

win=new Window("palette","FluentShadowUI",[0,0,200,100],{resizeable:true,independent:false,minimizeButton:false,maximizeButton:false,resizeable:false,});
but_1=win.add("button",[20,60,120,80],"Fluent Shadow");
but_1.helpTip="Select a layer";
pixel_size=win.add("dropdownlist",[20,20,120,42] ,["1px","2px","3px","4px","6px","8px","9px","12px","16px","24px","32px","48px","64px","80px","96px",""]);
pixel_size.helpTip="Choose your Shadow size";
win.center();
win.show();


but_1.onClick = function(){

if(pixel_size = "1px"){
var effectsGroup = app.project.activeItem.selectedLayers[0];
myEffect1px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0002").setValue(5.1);
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0003").setValue(180);
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0004").setValue(1);
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0005").setValue(4);
myEffect1px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0002").setValue(15.3);
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0003").setValue(180);
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0004").setValue(1);
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0005").setValue(4);
myEffect1px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0002").setValue(15.3);
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0003").setValue(180);
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0004").setValue(0.5);
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0005").setValue(4);
}else if(pixel_size = "2px"){
myEffect2px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
myEffect2px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0002").setValue(5.1);
myEffect2px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0003").setValue(180);
myEffect2px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0004").setValue(2);
myEffect2px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0005").setValue(6);
myEffect2px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0002").setValue(15.3);
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0003").setValue(180);
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0004").setValue(2);
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0005").setValue(6);
myEffect2px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0002").setValue(15.3);
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0003").setValue(180);
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0004").setValue(2);
myEffect2px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0005").setValue(6);

}else if(pixel_size = "3px"){
myEffect3px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
myEffect3px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0002").setValue(5.1);
myEffect3px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0003").setValue(180);
myEffect3px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0004").setValue(2);
myEffect3px.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0005").setValue(6);
myEffect3px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0002").setValue(15.3);
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0003").setValue(180);
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0004").setValue(2);
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0005").setValue(6);
myEffect3px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0002").setValue(15.3);
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0003").setValue(180);
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0004").setValue(2);
myEffect3px.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0005").setValue(6);

}...
}


Return to posts index

Andrei Popa
Re: set a function to call up a certain code based on a user dropdown choice
on Apr 3, 2018 at 8:33:18 am

I don't think that the if/else is the problem. You should call the selection by pixel_size.selection. However, when i have multiple choices, i usually use a switch statement. Easier to follow for me.

Andrei
My Envato portfolio.


Return to posts index

David Clabaugh
Re: set a function to call up a certain code based on a user dropdown choice
on Apr 3, 2018 at 3:36:16 pm

Thanks Andrei,

I will swap in the .selection

How would you put together a switch in this case?


Return to posts index


David Clabaugh
Re: set a function to call up a certain code based on a user dropdown choice
on Apr 3, 2018 at 4:26:05 pm

I have added the .selection parameter, but the function doesn't execute.


win=new Window("palette","The Fluent Shadow",undefined,{resizeable:true,independent:false,minimizeButton:false,maximizeButton:false,resizeable:false,});
but_1=win.add("button",[20,60,120,80],"Fluent Shadow");
but_1.helpTip="Select a layer";
pixel_size=win.add("dropdownlist",[20,20,120,42] ,["1px","2px","3px","4px","6px","8px","9px","12px","16px","24px","32px","48px","64px","80px","96px",""]);
pixel_size.selection = 0;
pixel_size.helpTip="Choose your Shadow size";
win.center();
win.show();


but_1.onClick = function(){

if(pixel_size.selection == "1px"){
var effectsGroup = app.project.activeItem.selectedLayers[0];
myEffect1px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0002").setValue(5.1);
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0003").setValue(180);
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0004").setValue(1);
effectsGroup.property("ADBE Effect Parade").property(1).property("ADBE Drop Shadow-0005").setValue(4);
myEffect1px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0002").setValue(15.3);
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0003").setValue(180);
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0004").setValue(1);
effectsGroup.property("ADBE Effect Parade").property(2).property("ADBE Drop Shadow-0005").setValue(4);
myEffect1px = effectsGroup.Effects.addProperty("ADBE Drop Shadow");
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0002").setValue(15.3);
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0003").setValue(180);
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0004").setValue(0.5);
effectsGroup.property("ADBE Effect Parade").property(3).property("ADBE Drop Shadow-0005").setValue(4);


Return to posts index

James Ronan
Re: set a function to call up a certain code based on a user dropdown choice
on Apr 5, 2018 at 3:42:34 pm

Try: pixel_size.selection.text === "1px"

Like this:

win=new Window("palette","The Fluent Shadow",undefined,{resizeable:true,independent:false,minimizeButton:false,maximizeButton:false,resizeable:false,});
but_1=win.add("button",[20,60,120,80],"Fluent Shadow");
but_1.helpTip="Select a layer";
pixel_size=win.add("dropdownlist",[20,20,120,42] ,["1px","2px","3px","4px","6px","8px","9px","12px","16px","24px","32px","48px","64px","80px","96px",""]);
pixel_size.selection = 0;
pixel_size.helpTip="Choose your Shadow size";
win.center();
win.show();


but_1.onClick = function(){

if(pixel_size.selection.text === "1px"){
alert("1px");
}

if(pixel_size.selection.text === "2px"){
alert("2px");
}

if(pixel_size.selection.text ==="3px"){
alert("3px");
}

}


Return to posts index

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