Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions I want to create automatic script for duplicate and move selected layer after every 2 layers

  • I want to create automatic script for duplicate and move selected layer after every 2 layers

    Posted by Palak Bhatt on July 23, 2020 at 9:00 pm

    I want to create automatic script for duplicate and move selected layer after every 2 layers

    For Example
    1 – Image — (I want this layer going to duplicate and move after 2 layers)
    2 – Solid Red
    3 – Solid Blue

    4 – Image
    5 – Solid Red
    6 – Solid Blue

    This thing continues by script
    I have tried duplicate script and move script below

    I don’t know how to both script collaborate
    Please Help if anyone has an idea


    -----------------------------------------------------------------------

    app.beginUndoGroup("Dublicate Layers");

    var thisComp = app.project.activeItem;
    var activeItem = app.project.activeItem;
    var activeLayers = activeItem.layers;

    for (var i = 0; i < thisComp.selectedLayers.length; i++){
    curLayer = thisComp.selectedLayers[i].duplicate();

    }

    app.endUndoGroup();

    ---------------------------------------------

    var activeItem = app.project.activeItem;
    var activeLayers = activeItem.layers;
    var i = 2;
    app.project.activeItem.layer(i).moveBefore(app.project.activeItem.layer(i+2));

    ------------------------------

    Palak Bhatt replied 6 years ago 1 Member · 1 Reply
  • 1 Reply
  • Palak Bhatt

    July 24, 2020 at 8:48 am

    Got the solution
    Coding is little rough but its worked

    Thanks

    app.beginUndoGroup("Dublicate Layers");

    var thisComp = app.project.activeItem;
    var activeItem = app.project.activeItem;
    var activeLayers = activeItem.layers;
    var d = app.project.activeItem.selectedLayers[0].index;

    for (var i = 0; i < thisComp.selectedLayers.length; i++){
    curLayer = thisComp.selectedLayers[i].duplicate();
    app.project.activeItem.layer(d).moveBefore(app.project.activeItem.layer(d+4));

    }

    app.endUndoGroup();

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