Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Duplicate the “Stroke” in any Vector Group via Scripting

  • Duplicate the “Stroke” in any Vector Group via Scripting

    Posted by Vincenzo Imbimbo on September 6, 2022 at 10:01 am

    Hello Guys, i’m trying to duplicate the “Stroke” in every vector group of all shape layers selected, but it’s not working, i don’t know what i’m doing wrong, this is the code:

    app.beginUndoGroup("myScript");

    var myLayers = comp.selectedLayers;

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

    tryStroke(myLayers[i].property("ADBE Root Vectors Group"))

    }

    function tryStroke(prop) {

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

    var subProp = prop.property(j);

    if (subProp.numProperties) {

    tryStroke(subProp)

    } else {

    if (subProp.matchName == "ADBE Vector Graphic - Stroke") {

    subProp.app.executeCommand(2080);

    }

    }

    }

    }

    app.endUndoGroup();


    Vincenzo Imbimbo replied 3 years, 8 months ago 2 Members · 7 Replies
  • 7 Replies
  • Andrei Popa

    September 6, 2022 at 5:00 pm

    This should work

    app.beginUndoGroup("myScript");
    var myLayers = comp.selectedLayers;
    for (var i = 0; i < myLayers.length; i++) {
    tryStroke(myLayers[i].property("ADBE Root Vectors Group"))
    }
    function tryStroke(prop) {
    for (var j = 1; j <= prop.numProperties; j++) {
    var subProp = prop.property(j);
    if (subProp.numProperties) {
    tryStroke(subProp)
    } else {
    if (subProp.matchName == "ADBE Vector Graphic - Stroke") {
    subProp.duplicate();
    }
    }
    }
    }
    app.endUndoGroup();
  • Vincenzo Imbimbo

    September 7, 2022 at 8:30 am

    Hello Andrei, thanks for your reply, unfortunately i’m still getting the same result (nothing happens), i don’t know if there’s a different approach to this, i want to duplicate the stroke of any selected layer (for every vector group) and then change the color of each stroke (assign 1 color to stroke 1 and another color to stroke 2).

  • Andrei Popa

    September 7, 2022 at 11:01 am

    Hey. Sorry, I did not test the code. Here is a working version. I changed the second for, because it was going infinite loop

    app.beginUndoGroup("myScript");
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++) {
    tryStroke(myLayers[i].property("ADBE Root Vectors Group"))
    }
    function tryStroke(prop) {
    for (var j = prop.numProperties; j >= 1; j--) {
    var subProp = prop.property(j);
    if (subProp.numProperties) {
    $.writeln(subProp.name)
    tryStroke(subProp)
    }
    if (subProp.matchName == "ADBE Vector Graphic - Stroke") {
    subProp.duplicate();
    }
    }
    }
    app.endUndoGroup();
  • Vincenzo Imbimbo

    September 7, 2022 at 11:35 am

    Thank you! This works perfectly, but is there any way to just duplicate it one time? I don’t want to duplicate everytime i press the button, something like “if this layer has Vector Groups with Stroke 1 and Stroke 2 then DON’T duplicate strokes”?

  • Vincenzo Imbimbo

    September 7, 2022 at 12:07 pm

    Also, i’m trying to change the colors but i can’t figure it out how to access to “Stroke 1” and “Stroke 2”, i tried this:

    if (subProp.matchName == “ADBE Vector Graphic – Stroke”) {

    subProp.duplicate();

    subProp.content(“Stroke 1”).color.setValue([0,0,0]);

    subProp.content(“Stroke 2”).color.setValue([1,1,1]);

    }

    But is not working 🙁

  • Andrei Popa

    September 8, 2022 at 8:41 am

    This should work

    app.beginUndoGroup("myScript");
    var myLayers = app.project.activeItem.selectedLayers;
    for (var i = 0; i < myLayers.length; i++) {
    tryStroke(myLayers[i].property("ADBE Root Vectors Group"))
    }
    function tryStroke(prop) {
    for (var j = prop.numProperties; j >= 1; j--) {
    var subProp = prop.property(j);
    if (subProp.numProperties) {
    $.writeln(subProp.name)
    tryStroke(subProp)
    }
    if (subProp.matchName == "ADBE Vector Graphic - Stroke" && !subProp.parentProperty("Stroke 2")) {
    subProp("ADBE Vector Stroke Color").setValue([0, 0, 0]);
    var str2 = subProp.duplicate();
    str2("ADBE Vector Stroke Color").setValue([1, 1, 1]);
    }
    }
    }
    app.endUndoGroup();
  • Vincenzo Imbimbo

    September 8, 2022 at 4:46 pm

    Thank you Andrei!! That is exactly what i need it, you are the best!

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