Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Script adding effect too many times.

  • Script adding effect too many times.

    Posted by Kevin Snyder on November 8, 2022 at 7:03 pm

    I have a script to apply an effect to selected layers and turn off an expression on the applied effect. It works when I have the layers of interest selected. However, if I have layer transform properties (position scale, opacity, rotation) selected when I run the script, the effect is applied several times to the layer with the selected transform properties. Is there a way to only apply the effect once per layer if transform properties are selected with the layers?

    function addPos(){

    app.beginUndoGroup("TEST");

    var myComp = app.project.activeItem;

    var myLayers = myComp.selectedLayers;

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

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

    var ffxFile = new File(colorFolderPath + encodeURI("/FP_position.ffx"));

    myComp.applyPreset(ffxFile);

    for (var i =0; i < myLayers.length; i++){

    var myProp = myLayers[i].effect("FP - Position")("Position Offset");

    myProp.expressionEnabled = false;

    }

    app.endUndoGroup();

    }

    addPos();

    Kevin Snyder replied 1 year, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    November 8, 2022 at 7:27 pm

    I haven’t tested this at all, but I would set it up like this:

    function addPos(){

    function deselectAll(theComp);

    for (var i = 1; i <= theComp.numLayers; i++){

    theComp.layer(i).selected = false;

    }

    }

    app.beginUndoGroup("TEST");

    var myComp = app.project.activeItem;

    var myLayers = myComp.selectedLayers;

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

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

    var ffxFile = new File(colorFolderPath + encodeURI("/FP_position.ffx"));

    for (var i =0; i < myLayers.length; i++){

    deselectAll(myComp);

    myLayers[i].selected = true;

    myLayers[i].applyPreset(ffxFile);

    var myProp = myLayers[i].effect("FP - Position")("Position Offset");

    myProp.expressionEnabled = false;

    }

    app.endUndoGroup();

    }

    addPos();

  • Kevin Snyder

    November 8, 2022 at 8:09 pm

    That’s great. Thank you.

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