Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
CoonKunsen
Topic Author
Posts: 2
Joined: Wed Apr 25, 2018 1:47 am

Remove All Expressions from Selected Layers

Wed Apr 25, 2018 1:56 am

Hi,

I found a script online which removes all Expressions from all layers within a composition. I tried to change it up so it only removes all expressions from selected layers and it works, but I always get an Alert after I run it that says "Unable to execute script at line 14. undefined is not an object". I was able to get rid of this error but than it only works on the last selected layer.

Also I don't really know what the recurse_children function does. Maybe someone knows a better way to do this?

Thanks in advance
Christian

app.beginUndoGroup("Remove all Expressions");
{
    var comp = app.project.activeItem;
    var layerNumber = comp.selectedLayers.length;
    var chosenLayers = comp.selectedLayers;
    
    if (layerNumber >= 1){

       for (var i = 0; i <= layerNumber; i++)
       {
          var layerNames = chosenLayers[i].index;
          recurse_children(comp.layers[layerNames]);
       }
    }    
    else{    
       alert('no layer selected');
    }

    function recurse_children(propParent)
    {
       if (propParent != null)
       {
          var prop;
          
          for (var i=1; i<=propParent.numProperties; i++)
          {
             prop = propParent.property(i);
             switch (prop.propertyType)
             {
                case PropertyType.PROPERTY:
                   // do action
                    if (prop.canSetExpression && prop.expression) prop.expression = '';
                   break;
                case PropertyType.INDEXED_GROUP:
                   recurse_children(prop);
                   break;
                case PropertyType.NAMED_GROUP:
                   recurse_children(prop);
                   break;
                default:
                   break;
             }
          }
       }
    }
    }
app.endUndoGroup();
 
wysee
Posts: 6
Joined: Mon Nov 21, 2016 9:24 am

Re: Remove All Expressions from Selected Layers

Wed Apr 25, 2018 2:33 am

Hi,
your loop is wrong. Selected Layers being an Array starting at index 0,  your loop should be ( i < layerNumber NOT <= ) like so:
 if (layerNumber >= 1){

       for (var i = 0; i < layerNumber; i++)
       {
          var layerNames = chosenLayers[i].index;
          recurse_children(comp.layers[layerNames]);
       }
    }    
    else{    
       alert('no layer selected');
    }
 
CoonKunsen
Topic Author
Posts: 2
Joined: Wed Apr 25, 2018 1:47 am

Re: Remove All Expressions from Selected Layers

Wed Apr 25, 2018 4:14 am

wysee wrote:
Hi,
your loop is wrong. Selected Layers being an Array starting at index 0,  your loop should be ( i < layerNumber NOT <= ) like so:

Awesome thanks :)

Who is online

Users browsing this forum: No registered users and 4 guests