Skip to main content
Inspiring
June 6, 2022
Question

extendscript after effects remove effect or slider by name ? using loop

  • June 6, 2022
  • 1 reply
  • 2494 views

how do i make this work i found online it dont seem to remove it when i click it.

 

i added auto color on a layer and clicked and press the button it don't remove it.

 

/**
 *Script removes defined effect from the selected compositions
 */

var mainWindow = new Window("palette", "Remove Effect", undefined); // main frame, column
mainWindow.orientation = "column";

var inputTextGroup = mainWindow.add("group", undefined, "Input Text Group");  // first group, row
inputTextGroup.orientation = "row";
var textInput = inputTextGroup.add("edittext", undefined, "ADBE AutoColor");
textInput.size = [100, 25];

var buttonGroup = mainWindow.add("group", undefined, "Button Group");
buttonGroup.orientation = "row";
var removeButton = buttonGroup.add("button", undefined, "Remove Effect");
removeButton.size = [100, 25];

mainWindow.center();
mainWindow.show();

removeButton.onClick = function (){
    
    app.beginUndoGroup("Remove Effect");
                       var effectName = textInput.text;
                       
                       //Work with selected compositions only
                        for (var k = 1; k <= app.project.numItems; k++){
                                if ((app.project.item(k) instanceof CompItem) && app.project.item(k).selected) {
                                    
                                     var myLayers = app.project.item(k).layers;
                                     
                                            for (var i = 1; i <= myLayers.length; i ++) { 
                                   
                                                     var CurrLayer = app.project.item(k).layer(i);  // select curr layer
                                                                                                                                               
                                                           // 1. Remove effect
                                                           if (CurrLayer.Effects.property(effectName)){
                                                               
                                                               CurrLayer.Effects.property(effectName).remove();  // removes selected effect
                                                               
                                                              }                
                                                           }                       
                                                        }                              
                                                     }
            //         app.executeCommand(app.findMenuCommandId("Save a Copy As..."));   // uncomment to save if needed
            app.endUndoGroup();
}
This topic has been closed for replies.

1 reply

Inspiring
June 7, 2022

does this look ok it seems to work on selected layer.

if you think you can make it better please share.

 

one issue now is when i try and remove slider control i get error on extend script null is not an object

ADBE Slider Control   < throws this error when i use this.

but if i use ADBE AutoColor to remove auto color it works no errors

 

var thisComp = app.project.activeItem;
var hasEffect = false;
var thisLayer = thisComp.selectedLayers[0];
var shapeGroupCollection = thisLayer.property(2);

var comp = app.project.activeItem;
var selectedLayers = comp.selectedLayers;
var layer = comp.selectedLayers[0];
//for (var i = 0; i < selectedLayers.length; i++) {
for (var i = 1; i <= layer.property("Effects").numProperties; i++) {
    //selectedLayers[i].selected = false;
//layer.property("Effects").property("ADBE AutoColor").remove(); 
layer.property("Effects").property("ADBE Slider Control").remove(); 
}

 

Mathias Moehl
Community Expert
Community Expert
June 7, 2022

Your code has several problems.

First, if several effect need to be deleted on the same layer, it won't delete all of them. You go over the effects from first to last. If you now delete the first effect, the second one will become the first one and then your code won't check this second effect, which has now become the first one.

 

To solve this, you could go backwards over the effects:

 

 

for (var i =  layer.property("Effects").numProperties; i >= 1; i--)

 

 

 

Second issue: you loop over the effects with the variable i, but inside the loop you don't look at effect number i. Either you look at effect number i, check its match name and if it is the one you are looking for, delete it. Or even simpler, you use a while loop, to repeat the delete as long as such an effect exists:

 

while(layer.property("Effects").property("ADBE Slider Control")){
layer.property("Effects").property("ADBE Slider Control").remove();
}

 

With Automation Blocks, the code to delete all slider control effects on the selected layers with a for loop looks like this:

And the variant with while would be

 

Also note that Automation Blocks comes with an ready to use example "Delete All Occurrences of Effect", which asks for a search word and then deletes all effects whose name contains this search word:

Cheers

Mathias

 

 

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Inspiring
June 7, 2022

Mathias thank you for taking the time to share your excellent post.

can you kindly show me an example of how to remove a specific effect using a string rather than removing all the controls this could be problematic at some point when working on live projects as it may contain controls already assigned to other comps+controls?

 

please kindly share how to remove effect using a custom string name

slider control name = speed

now remove all slider that contains the string speed.

with one example i can play and learn further thank you Mathias