Copy link to clipboard
Copied
I Wish Select All Layer One By One Sequentially. Like 1,2,3,4 so on.
Thanks in Advance
Presuming that a layer has a unique name (otherwise the first layer with the name will be targeted, which may not be the one you require):
var selectLayer1 = app.activeDocument.artLayers.getByName("Layer 1");
app.activeDocument.activeLayer = selectLayer1;
or
app.activeDocument.activeLayer = app.activeDocument.layers["Layer 1"];
The layers collection can also be used, it starts the indexing at zero, so the 8th layer from the top would be #7:
var selectLayer = app.activeDocum
...
In your script, right after the line
var ids = getLayersIDs (); // getting ids of selected layers
paste this code:
ids.sort(cmp);
function cmp(a, b)
{
try {
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), a);
var b1 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));
var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));
...
Your 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],dimA
...
Copy link to clipboard
Copied
You can select multiple individual layers by holding the CTRL key and clicking each layer... ? ...
but not really sure what you mean? 🤔😮
Copy link to clipboard
Copied
@ Ro Hackett It's a scripting question.
@ Kailash0D4D what should happen after Layer 1 is selected, before Layer 2 is selected?
There are actually two layers per "visual layer set", one being a color fill layer and one a text layer. The layer index order is not sequential. All of the fill layers come first, then the text layers (not fill then text, fill then text etc).
So which exact layer should be selected "sequentually"?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Just in case you are attempting to create a montage template, JJMack has done a lot of work in this area which could save you developing your own script:
Free Photoshop Photo Collage and Mockup Toolkit
Copy link to clipboard
Copied
@ Kailash0D4D I'm just a beginner so I may have this wrong, however, I believe that you have four methods to select a layer:
getByName = Probably the most obvious, best if all layers have a unique name to target
itemIndex # = Number may change if layers are added or removed
id # = Unique, static, does not change if layers are added or removed
It will probably depend on the template setup and how the end user will use/modify the template on what method is preferred.
P.S. I'm guessing that a for loop could probably cycle through all layers and and perform various steps on each layer.
Copy link to clipboard
Copied
This script can be used to identify a selected layer's Name, itemIndex # or id # –
EDIT 18th Jan 2021: I have added a few other informative properties to the inspector, just for fun!
EDIT 31st May 2021: old script removed, new code posted below!
Copy link to clipboard
Copied
Presuming that a layer has a unique name (otherwise the first layer with the name will be targeted, which may not be the one you require):
var selectLayer1 = app.activeDocument.artLayers.getByName("Layer 1");
app.activeDocument.activeLayer = selectLayer1;
or
app.activeDocument.activeLayer = app.activeDocument.layers["Layer 1"];
The layers collection can also be used, it starts the indexing at zero, so the 8th layer from the top would be #7:
var selectLayer = app.activeDocument.layers[7];
app.activeDocument.activeLayer = selectLayer;
Selecting a single layer using the unique/static layer id value –
selectLayerById(1); // Enter layer.id number
function selectLayerById(id)
/* https://graphicdesign.stackexchange.com/questions/130739/photoshop-scripting-applying-changes-only-to-selected-artboards */
{
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putIdentifier(charIDToTypeID('Lyr '), id);
desc1.putReference(charIDToTypeID('null'), ref1);
executeAction(charIDToTypeID('slct'), desc1, DialogModes.NO);
}
Select single layer via index value –
/* Select layer via index value, indexing starts at zero (bottom layer) */
selectLayerByIndex(8); // the 9th layer, starting from 0
function selectLayerByIndex(index) {
/* https://github.com/ES-Collection/Photoshop-Scripts/blob/master/Remove%20Unused%20Layers.jsx */
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO );
}
Copy link to clipboard
Copied
Bump... So how did you go?
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);
};
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.
Copy link to clipboard
Copied
Yes, I want to sort layer From right to left.
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()
Copy link to clipboard
Copied
Don't reflect any layer from left to right
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.
Copy link to clipboard
Copied
I want to rename the layer left to right form. I have show the image. check it
Copy link to clipboard
Copied
Your 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()
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Don't work, Please anyone help me Sequentially layer left to right.
Thanks in Advance
Copy link to clipboard
Copied
स्पष्ट कमबख्त नहीं
Copy link to clipboard
Copied
It obviously works, do you mean that you can't make it work?
Copy link to clipboard
Copied
Well.
Here, suppose you have an eight-layer document.
How are you going to rename the layers (rectangles, but layers can come from several parts too)?
Copy link to clipboard
Copied
In this condition, Every template between gaps and i want to select layer from left to right .
Copy link to clipboard
Copied
The layers are numbered from left to right.
Confirm or refute the sequence, but only reasonably, and not like this: "i want ...".
Copy link to clipboard
Copied
Yes, I want this, Please How to create script
Please help me
Thanks in Advance