• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

duplicate and movebefore layerSelected

Explorer ,
Sep 21, 2022 Sep 21, 2022

Copy link to clipboard

Copied

Hi everyone

I want to duplicate selected layers
Then put the duplicated layers on top of the selected layers

I tried it for an hour but it was all messed up
can someone help me, thanks a lot

var comp  = app.project.activeItem; 
var layers= comp.selectedLayers;
var numLayers = layers.length;
        if (numLayers > 0) {
            for (var i = 0; i < numLayers; i++) { 
                layers[i].duplicate();
                layers[i].moveAfter(comp.layer(layers[i].index+1));
            }
    }

 

image_2022-09-22_105353672.png

TOPICS
Scripting

Views

317

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 21, 2022 Sep 21, 2022

Copy link to clipboard

Copied

I did it but it's still not ok

var comp  = app.project.activeItem; 
var layers= comp.selectedLayers;
var numLayers = layers.length;
var myArray=[];
app.beginUndoGroup("Set Marker");
if (numLayers > 0) {
    for (var i = 0; i < numLayers; i++) { 
        myArray.push(layers[i].name); //Get layer name selected
    }
    for (var i = 0; i < myArray.length; i++) { 
        comp.layer(myArray[i]).duplicate(); // Duplicate
    }
    var indexLayer=comp.layer(myArray[0]).index; // Get index
    for (var i = 0; i < myArray.length; i++) { 
        comp.layer(myArray[i]).moveBefore(comp.layer(indexLayer-1));
    }
    }
    app.endUndoGroup();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2022 Sep 22, 2022

Copy link to clipboard

Copied

LATEST

I would not recommend to rely on layer names - this always causes trouble when you have multiple layers with the same name. Better follow the logic of my Automation Blocks example.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 21, 2022 Sep 21, 2022

Copy link to clipboard

Copied

Why do you create a new loop everytime? Of course your variable i will not carry over and the index be all messed up because after the duplication it shifts by +1. Do it all in one.

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2022 Sep 22, 2022

Copy link to clipboard

Copied

Here is an implementation with Automation Blocks:Screenshot 2022-09-22 at 09.40.47.png

 

You also find it now in our Community Library at

Layer/Duplicate/Duplicate Selected Layers and Move Above First Selected Layer

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines