I want Sequentially Layer Left to Right

New Here ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

In this Script, From Bottom to Top Level Change The Rename One By One. I wish Left To Right Serial Wise.

 

 

var newName = "Layer";
var ids = getLayersIDs(); // getting ids of selected layers

//for each id in the list
for (var i = 0; i < ids.length; i++)
{
// select the layer first (well, artboard in this case)
selectById(ids[i]);

//rename it to "my name 1", "my name 2", etc
activeDocument.activeLayer.name = newName + " " + (i + 1);
}

// this will get IDs of selected layers/groups/artboards
function getLayersIDs()
{
var lyrs = [];
var lyr;
var ref = new ActionReference();
var desc;
var tempIndex;
var ref2;

ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayers"));
ref.putEnumerated(charIDToTypeID('Dcmn'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));

var targetLayers = executeActionGet(ref).getList(stringIDToTypeID("targetLayers"));
for (var i = 0; i < targetLayers.count; i++)
{
tempIndex = 0;
ref2 = new ActionReference();
try
{
activeDocument.backgroundLayer;
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex());
try
{
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex")) - 1;
}
catch (e)
{
tempIndex = 0;
}
}
catch (o)
{
ref2.putIndex(charIDToTypeID('Lyr '), targetLayers.getReference(i).getIndex() + 1);
desc = executeActionGet(ref2);
tempIndex = desc.getInteger(stringIDToTypeID("itemIndex"));
}

lyrs.push(desc.getInteger(stringIDToTypeID("layerID")));
}

return lyrs;
};

// this will select a layer by ID
function selectById(id)
{
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
};

TOPICS
Actions and scripting, How to, Problem or error

Views

825

Likes

translate

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 Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

What you need to do is get the bounds for the layers, then use that to sort the order, so you can then rename them on that sort order.

Likes

translate

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
New Here ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

Yes, I want to sort layer From right to left.

Likes

translate

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 Professional ,
Apr 30, 2021 Apr 30, 2021

Copy link to clipboard

Copied

Try this:

 

#target photoshop
var doc = activeDocument;
var artArray = [];
var count = 0;
for(var i=0;i<doc.layers.length;i++){
    doc.activeLayer = doc.layers[i];
    if(isArtBoard ()){
        var dimArt = getArtboardDimensions ()
        artArray.push([dimArt[0],dimArt[1],doc.activeLayer])
        count++
        }
    }

artArray.sort(function(a,b){return (a[0]-b[0]) || (a[1]-b[1])});

for (i=0;i<artArray.length;i++){
    artArray[i][2].name = 'Artboard ' + (i+1);
    }

function isArtBoard()
{
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    return executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
}; // end of isArtBoard()

function getArtboardDimensions()
{
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
    var left = desc.getDouble(stringIDToTypeID("left"));
    var top = desc.getDouble(stringIDToTypeID("top"));
    return [left, top]
}; // end of getArtboardDimensions()

Likes

translate

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
New Here ,
May 01, 2021 May 01, 2021

Copy link to clipboard

Copied

Don't reflect any layer from left to right

Likes

translate

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 Professional ,
May 01, 2021 May 01, 2021

Copy link to clipboard

Copied

I'm not sure what you mean, by, "Don't reflect any layer from left to right." The script should just rename the artboards in order: left to right.

Likes

translate

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
New Here ,
May 01, 2021 May 01, 2021

Copy link to clipboard

Copied

I want to rename the layer left to right form. I have show the image. check it

45.JPG

Likes

translate

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 Professional ,
May 05, 2021 May 05, 2021

Copy link to clipboard

Copied

Likes

translate

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 Professional ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

You're first screen shot showed that you wanted the artboard numbered top to bottom then left to right, which the previous script that I posted did. You're second screen shot shows left to right then top to bottom. So this script does that:

#target photoshop
var doc = activeDocument;
var artArray = [];
var count = 0;
for(var i=0;i<doc.layers.length;i++){
    doc.activeLayer = doc.layers[i];
    if(isArtBoard ()){
        var dimArt = getArtboardDimensions ()
        artArray.push([dimArt[0],dimArt[1],doc.activeLayer])
        count++
        }
    }

artArray.sort(function(a,b){return (a[1]-b[1]) || (a[0]-b[0])});

for (i=0;i<artArray.length;i++){
    artArray[i][2].name = 'Artboard ' + (i+1);
    }

function isArtBoard()
{
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    return executeActionGet(ref).getBoolean(stringIDToTypeID("artboardEnabled"));
}; // end of isArtBoard()

function getArtboardDimensions()
{
    var ref = new ActionReference();
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref).getObjectValue(stringIDToTypeID("artboard")).getObjectValue(stringIDToTypeID("artboardRect"));
    var left = desc.getDouble(stringIDToTypeID("left"));
    var top = desc.getDouble(stringIDToTypeID("top"));
    return [left, top]
}; // end of getArtboardDimensions()

Likes

translate

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