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

Flip only selected layers one by one

Engaged ,
Jul 01, 2023 Jul 01, 2023

Copy link to clipboard

Copied

With following script we can flip all layers one by one: 

//Script to flip all layers horizontally
//Just collect all layers in an array and then flip each one by looping
//if background layer is present it has to be transformed into a normal layer, then flipped, and then turned back into a
//Not really recomended for multiple frame animations.

//get the document
doc = app.activeDocument;

//get the array with all the layers
allLayers = [];
allLayers = collectAllLayers(doc, allLayers);

//loop and flip
for (var i = 0; i < allLayers.length; i++) {
    //flip all layers that aren't backgorund
    if (allLayers[i].isBackgroundLayer == false) {
        
        var vis = allLayers[i].visible;                                         //save whether the layer was visible or not

        allLayers[i].visible = true;                                            //set to visible so the layer is editable
        allLayers[i].resize(-100, undefined, AnchorPosition.MIDDLECENTER);      //flip the layer
        allLayers[i].visible = vis;                                             //set the visibility back to what it was before editing
    }

    else {
    //flip the backgorund layer (if existant)
        allLayers[i].visible = true;                                            //set to visible so the layer is editable
        allLayers[i].isBackgroundLayer = false;                                 //transform background layer into normal layer
        allLayers[i].resize(-100, undefined, AnchorPosition.MIDDLECENTER);      //flip it
        allLayers[i].isBackgroundLayer = true;                                  //turn back into backgorund layer
        allLayers[i].visible = vis;                                             //set the visibility back to what it was before editing
    }
}

function collectAllLayers (doc, allLayers){
    //returns array containing all posible layers.
    for (var m = 0; m < doc.layers.length; m++){
        var theLayer = doc.layers[m];
        if (theLayer.typename === "ArtLayer"){
            allLayers.push(theLayer);
        }else{
            collectAllLayers(theLayer, allLayers);
        }
    }
    return allLayers;
}

 

Now if i want to flip only selected layers one by one, what changes i must apply to above script? 

TOPICS
Actions and scripting

Views

139

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
Adobe
Community Expert ,
Jul 01, 2023 Jul 01, 2023

Copy link to clipboard

Copied

LATEST

You already have a discussion thread open about this same script. Please do not duplicate.

https://community.adobe.com/t5/photoshop-ecosystem-discussions/flip-multiple-objects-selection-one-b...

 

Thread Locked - Dave

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