Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions set a function to call up a certain code based on a user dropdown choice

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

    Posted by David Clabaugh on April 3, 2018 at 1:00 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);

    }...
    }

    James Ronan replied 8 years, 1 month ago 3 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    April 3, 2018 at 8:33 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.

  • David Clabaugh

    April 3, 2018 at 3:36 pm

    Thanks Andrei,

    I will swap in the .selection

    How would you put together a switch in this case?

  • David Clabaugh

    April 3, 2018 at 4:26 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);

  • James Ronan

    April 5, 2018 at 3:42 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");
    }

    }

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy