Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Add Trim Paths to any selected shape layers with a Script

  • Add Trim Paths to any selected shape layers with a Script

    Posted by Vincenzo Imbimbo on May 26, 2022 at 4:00 pm

    Hello guys, anyone can help me to add a Trim Paths to any selected shape layers? I just want to add ONE trim paths to each layer, no matter how many shapes it has inside.

    Any help?

    This is the property path to the Trim Paths:
    layers[i].property(“ADBE Root Vectors Group”).property(“ADBE Vector Filter – Trim”)

    I also want to access the “Start” and “End” of the trim paths to add an expression to each one.

    This is the property path for “Start”:

    layers[i].property(“ADBE Root Vectors Group”).property(“ADBE Vector Filter – Trim”).property(“ADBE Vector Trim Start”)

    And this is the property path for “End”:

    layers[i].property(“ADBE Root Vectors Group”).property(“ADBE Vector Filter – Trim”).property(“ADBE Vector Trim End”)

    I think the code should be something like this:

    var comp = app.project.activeItem;

    var layers = comp.selectedLayers;


    if(layers.length == 0){

    alert("You must select a layer");

    } else {

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

    layers[i].property("ADBE Root Vectors Group").//add??//property("ADBE Vector Filter - Trim")

    //and then://

    layers[i].property("ADBE Root Vectors Group").property("ADBE Vector Filter - Trim").property("ADBE Vector Trim Start").//expression = "my expression"??//

    Andrei Popa replied 3 years, 11 months ago 2 Members · 8 Replies
  • 8 Replies
  • Andrei Popa

    May 27, 2022 at 6:51 am

    I think this is what you need

    var comp = app.project.activeItem;

    var layers = comp.selectedLayers;

    if (layers.length == 0) {

    alert("You must select a layer");

    } else {

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

    if (layers[i] instanceof ShapeLayer) {

    var myTrim = layers[i].property("ADBE Root Vectors Group").addProperty("ADBE Vector Filter - Trim");

    //and then://

    myTrim("ADBE Vector Trim Start").expression = "value";

    }

    }

    }

  • Vincenzo Imbimbo

    May 27, 2022 at 3:46 pm

    Thank you Andrei!! This is what i need it, but there’s a little problem, if i execute the script again it will add another Trim Paths to each selected layer, i just want to have 1 Trim Path, no matter how many times i execute the script, any way to fix this? Something like “if this shape layer already has a trim path then don’t add a trim paths”, thank you!

  • Andrei Popa

    May 27, 2022 at 4:49 pm

    I think this will be the fastest way

    var comp = app.project.activeItem;

    var layers = comp.selectedLayers;

    if (layers.length == 0) {

    alert("You must select a layer");

    } else {

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

    if (layers[i] instanceof ShapeLayer) {

    var myTrim = layers[i].property("ADBE Root Vectors Group")("ADBE Vector Filter - Trim")

    ? layers[i].property("ADBE Root Vectors Group")("ADBE Vector Filter - Trim")

    : layers[i].property("ADBE Root Vectors Group").addProperty("ADBE Vector Filter - Trim");

    //and then://

    myTrim("ADBE Vector Trim Start").expression = "value";

    }

    }

    }

  • Vincenzo Imbimbo

    May 31, 2022 at 8:40 am

    Hi again Andrei, thank you for your reply, i tried the code but i’m getting a syntax error saying that “?” doesn’t have an assigned value. What i am missing?

  • Vincenzo Imbimbo

    May 31, 2022 at 8:57 am

    Oh nevermind, it was the “;” that i was keeping at the end of “var myTrim…” so the ternary operator was missing the condition, but now is working perfectly, thank you so much!!

  • Vincenzo Imbimbo

    May 31, 2022 at 9:06 am

    Is there any way to apply the same Ternary Operator to this line of code?

    var durationIn = myLayers[i].Effects.addProperty(“ADBE Slider Control”);

    durationIn.name = “IN”;

    I want to add to each selected layer a slider control named “IN” but if i run the script again i don’t want to add another slider control named “IN”, i just want to overwrite the value of that slider with a new input. Can you help me? Thanks again!

  • Vincenzo Imbimbo

    May 31, 2022 at 9:45 am

    I figured it out with this:

    var durationIn = myLayers[i].Effects("ADBE Slider Control")

    ? myLayers[i].Effects("ADBE Slider Control")

    : myLayers[i].Effects.addProperty("ADBE Slider Control");

    durationIn.name = "IN";

    var durationOut = myLayers[i].Effects("ADBE Slider Control")

    ? myLayers[i].Effects("ADBE Slider Control")

    : myLayers[i].Effects.addProperty("ADBE Slider Control");

    durationOut.name = "OUT";

    But the problem is that the ternary operator just read if the layer has a “Slider Control” and i need it to be specific with “IN” and “OUT” sliders. Sorry for asking so much questions, i’m really newbie with JS.

  • Andrei Popa

    May 31, 2022 at 2:01 pm

    You can use the name of the effect instead of its matchname if you want to. Like this:

    var durationIn = myLayers[i].Effects("IN")

    ? myLayers[i].Effects("IN")

    : myLayers[i].Effects.addProperty("ADBE Slider Control");

    durationIn.name = "IN";

    var durationOut = myLayers[i].Effects("OUT")

    ? myLayers[i].Effects("OUT")

    : myLayers[i].Effects.addProperty("ADBE Slider Control");

    durationOut.name = "OUT";

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