Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions script to copy multiple paths from one layer to multiple masks on another layer?

  • script to copy multiple paths from one layer to multiple masks on another layer?

  • constanti dinu

    December 3, 2021 at 1:52 pm

    hi,

    for starters, i have never wrote scripts in AE, only expression, so saying im new to this is an understatement.

    i have a shape layer with 300+ paths and i need to copy every path into an adjustment layer as a mask. i have done this manually by copying the path from the shape, add a new mask in the adjustment layer, and paste it there, but because i have to do this a lot of times, i kinda need a script. i tried my best with what’s below, so far ive managed to copy the path, add mask, paste the path as a mask, delete the first path. any ideas how to make this a loop?

    var myComp = app.project.activeItem;

    var mySourceLayer = myComp.layer(“de sters”);

    var myPath = mySourceLayer.property(“Contents”).property(1).property(“Path”);

    mySourceLayer.selected = true;

    myPath.selected = true;

    app.executeCommand(19); //Copy

    myPath.selected = false;

    mySourceLayer.selected = false;

    var myShape = myPath.value;

    var myDestLayer = myComp.layer(“1”);

    var myNewMask = myDestLayer.property(“Masks”).addProperty(“Mask”);

    var myNewPath = myNewMask.property(“Mask Path”);

    //myNewPath.setValue(myShape);

    myDestLayer.selected = true;

    myNewMask.selected = true;

    myNewPath.selected = true;

    app.executeCommand(20); //Paste

    myDestLayer.selected = false;

    mySourceLayer.selected = true;

    myPath.selected = true;

    app.executeCommand(18); //Copy

  • Andrei Popa

    December 3, 2021 at 3:25 pm

    Hi Constanti.

    I am not 100% sure how the paths are organized inside your layer, but this or something close to this should work.

    var myComp = app.project.activeItem;
    var mySourceLayer = myComp.layer("de sters");
    var myDestLayer = myComp.layer("1");
    for (var i = 1; i <= mySourceLayer("Contents").numProperties; i++) {
    var myPath = mySourceLayer("Contents")(i)("Path") ;
    if(myPath !== null) copyPathToMask(mySourceLayer, myPath, myDestLayer);
    }
    function copyPathToMask(mySourceLayer, myPath, myDestLayer) {
    mySourceLayer.selected = true;
    myPath.selected = true;
    app.executeCommand(18); //Cut
    mySourceLayer.selected = false;
    var myNewMask = myDestLayer.property("Masks").addProperty("Mask");
    var myNewPath = myNewMask.property("Mask Path");
    myDestLayer.selected = true;
    myNewMask.selected = true;
    myNewPath.selected = true;
    app.executeCommand(20); //Paste
    myDestLayer.selected = false;
    }

  • constanti dinu

    December 3, 2021 at 3:44 pm

    worked perfectly, mersi frumos Andrei

Viewing 1 - 3 of 3 posts

Log in to reply.

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