• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

Explorer ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

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();
}
TOPICS
Expressions , Scripting

Views

392

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

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(); 
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2022 Jun 06, 2022

Copy link to clipboard

Copied

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:

Screenshot 2022-06-07 at 08.40.26.png

And the variant with while would be

Screenshot 2022-06-07 at 09.00.07.png

 

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:

Screenshot 2022-06-07 at 08.45.59.png

Cheers

Mathias

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

am building a custom script for my use and I don't want to download 3rd party as I cant use it in my script.

am making all in one tool so all the shortcut I need is being added to the script am making.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

once its done i will share it with you and public

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

while loop works flawlessly lol.

is it possible to remove control + effects using custom strings as we rename the effects and controls sir.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

Yes, you can simply use the the name you gave the slider instead of the matchname. This removes all effects which you named "speed":

while(layer.property("Effects").property("Speed")){
layer.property("Effects").property("Speed").remove();
}

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

bro Mathias i se that while loop stays running unlimited time so it can be problem unless we can stop it ?

also can you share a code how to remove using custom string.

i am testing your script and i am unable to remove a slider using string name also?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

bug with your script.

cant close when i press red x.

when i try delete a effect from library nothing happens

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

had to uninstall it as it started to crash my after effects 2022 on startup always now.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

I guess you renamed the "Speed" in only one of the two occurrences of the script? If you do that, it loops forever, of course.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

sir the do-while is open and it is on a continuous loop which will choke after-effects and freeze it.

this needs to be modified so it stops after sometime of checking all controls are gone.
while(layer.property("Effects").property("Speed")){

layer.property("Effects").property("Speed").remove();

}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 08, 2022 Jun 08, 2022

Copy link to clipboard

Copied

LATEST

it does such a check:

layer.property("Effects").property("Speed")
will evaluate to false as soon as there does not exist a property "Speed" in the Effects of the layer anymore and that should stop the while loop.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines