Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions AE Script “Else” isn’t working

  • AE Script “Else” isn’t working

  • Kevin Snyder

    September 14, 2020 at 5:46 am

    I’m trying to create a script that will run different functions based on input (yes/no) from the user. I can get either set of functions to work, but I can’t get them both to work based on the user’s input. If true (third line), the script will run the functions of child and proximity. If I set it to false, it will run the function custom. For some reason, yes or no is running the same set of functions. Here’s the code:

    app.beginUndoGroup("Proximity");

    if (confirm("Standard transform properties?"));

    if (true){

    function child(){

    var myComp = app.project.activeItem;

    var scriptFolderPath = File($.fileName).path;

    var colorFolderPath = scriptFolderPath + encodeURI("/preset");

    var ffxFile = new File(colorFolderPath + encodeURI("https://cdn.creativecow.net/Proximity Child.ffx"));

    myComp.applyPreset(ffxFile);

    }

    child()

    function proximity(){

    var controller = app.project.activeItem.layers.addNull();

    controller.name = "proximity";

    controller.enabled = true;

    var scriptFolderPath = File($.fileName).path;

    var colorFolderPath = scriptFolderPath + encodeURI("/preset");

    var ffxFile = new File(colorFolderPath + encodeURI("https://cdn.creativecow.net/Proximity Master.ffx"));

    controller.applyPreset(ffxFile);

    }

    proximity()

    }

    else

    {

    function custom(){

    var myComp = app.project.activeItem;

    var scriptFolderPath = File($.fileName).path;

    var colorFolderPath = scriptFolderPath + encodeURI("/preset");

    var ffxFile = new File(colorFolderPath + encodeURI("https://cdn.creativecow.net/Proximity Custom.ffx"));

    myComp.applyPreset(ffxFile);

    }

    custom()

    }

    app.endUndoGroup();

  • Stephen Dixon

    September 14, 2020 at 6:02 am

    That’s not how if()-then commands work. The syntax is
    if (expression-that-evaluates-to-true-or-false){doStuff()}else{doOtherStuff()}

    Your code has if(true) on the third line, and since true is the javascript constant boolean true the condition will always evaluate to true, so the first block of code will get executed.

    get rid of the semicolon on line 2 and all of line 3 and it should work.

  • Kevin Snyder

    September 14, 2020 at 3:33 pm

    Great! Thank you. That works.

Viewing 1 - 3 of 3 posts

Log in to reply.

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