Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Apply preset, set values

  • Apply preset, set values

  • Tudor Baican

    November 20, 2022 at 4:47 pm

    Hello friends,

    my script should apply to any selected layer a preset and change the slider value of the preset.

    So far so good. It works to the point where the slider value should be set.

    It only change the values from the first layer.

    How can I set the values from all layers? Thanks for your help.

    if (app.project.activeItem != null || !app.project.activeItem instanceof CompItem){

    var mySelectedLayers = app.project.activeItem.selectedLayers;

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

    var myLayer = mySelectedLayers[i];

    var thisScriptPath = $.fileName;

    var relativePath = thisScriptPath.substring(0, thisScriptPath.lastIndexOf(“/”));

    var myPreset = File(relativePath+”/Assets/mySlider.ffx”);

    var hasController = false;

    for(var j=1; j<=myLayer.effect.numProperties; j++){

    if(myLayer.effect.property(j).name == “mySlider”){

    hasController = true;

    };

    };

    if(!hasController){

    myLayer.applyPreset(myPreset);

    myLayer.effect(‘mySlider’).property(‘Slider’).setValue(100); // < This value should be changed.

    myLayer.selected = false;

    };

    };

    };

  • Filip Vandueren

    November 21, 2022 at 1:46 pm

    Possibly, when you use the first applyPreset, or setValue, the other layers get deselected, so looping through selectedLayers stops.

    check if this works:

    var mySelectedLayers = app.project.activeItem.selectedLayers.slice();

    slicing the array should give a copy of the list of layers instead of a reference to the same object

  • Tudor Baican

    November 21, 2022 at 3:03 pm

    Ok, think I got it.

    The <b class=””>applyPreset function apply the preset to all selected layers. That means that all the layers needs to deselect. In the for iteration the layer needs to be select and then deselect after the preset is applied.

    var mySelectedLayers = app.project.activeItem.selectedLayers;
    app.executeCommand(2004); // Deselect all Layer
    var relativePath = $.fileName.substring(0, $.fileName.lastIndexOf("/"));
    var myPreset = File(relativePath+"/myPreset.ffx");
    for(var i=0; i<mySelectedLayers.length; i++){
    var myLayer = mySelectedLayers[i];
    var hasController = false;
    myLayer.selected = true;
    for(var k=1; k<=myLayer.effect.numProperties; k++){
    if(myLayer.effect.property(k).name == "myPreset.ffx"){
    hasController = true;
    };
    };
    if(!hasController){
    myLayer.applyPreset(myPreset);
    myLayer.selected = false;
    };
    };
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