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
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"));
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), b);
var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));
var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));
return l1 > l2;
}
catch (e) { throw(e); }
}
Copy link to clipboard
Copied
This is right ,Please check it
var ids = getLayersIDs (); // getting ids of selected layers
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"));
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), b);
var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));
var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));
return l1 > l2;
}
catch (e) { throw(e); }
}
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;
};
Copy link to clipboard
Copied
Please Add The Rename Each Layer From Left to right like layer1,layer2,layer3 etc
Copy link to clipboard
Copied
var newName = "Layer";
var ids = getLayersIDs(); // getting ids of selected layers
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"));
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), b);
var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));
var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));
return l1 - l2;
}
catch (e) { throw(e); }
}
//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
Yes, sort of like that. But your code is not complete as in the first post. It won't work.
There I have a mistake !!!!!!!!!.
Correct
return l1> l2;
to the
return l1 - l2;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
OK
var newName = "Layer";
var ids = getLayersIDs(); // getting ids of selected layers
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("width"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var doc_w = executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("width"));
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("height"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var doc_h = executeActionGet(r).getUnitDoubleValue(stringIDToTypeID("height"));
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 t1 = b1.getUnitDoubleValue(stringIDToTypeID("top"));
var l1 = b1.getUnitDoubleValue(stringIDToTypeID("left"));
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("bounds"));
r.putIdentifier(stringIDToTypeID("layer"), b);
var b2 = executeActionGet(r).getObjectValue(stringIDToTypeID("bounds"));
var t2 = b2.getUnitDoubleValue(stringIDToTypeID("top"));
var l2 = b2.getUnitDoubleValue(stringIDToTypeID("left"));
t1 = 100-Math.round(doc_h/t1)*100;
t2 = 100-Math.round(doc_h/t2)*100;
var x1 = l1 + t1*doc_w;
var x2 = l2 + t2*doc_w;
return x1 - x2;
}
catch (e) { throw(e); }
}
//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
Copy link to clipboard
Copied
Where did you see there from left to right and from top to bottom? I see no logic.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I do not understand you. Be clearer.
Copy link to clipboard
Copied
Yes everything is fine, But I will put on 12x36 page. The script is entire left so I with 12x18 page is good working but 12x36 page is enitre left so
Copy link to clipboard
Copied
Post the PSD with the problem. I'll see.
And explain what you are doing, which layers you are selecting.
Copy link to clipboard
Copied
I have put on 12x36 page, The script is entire left Please check it.
1:- Create 12x36 Page
2:- Create 8 Layer
3:- Run the Script
4:- The result is entire left to right.
12x18 Page is good working and 4 layer also good working, Just 8 Layer to entire left to right,
Please see the image below
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Did you understand that
Copy link to clipboard
Copied
Did you check it , let me know Did you understand the problem
Copy link to clipboard
Copied
Hey people.
Does anyone understand what he wants.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanku so much, I expect you can do it, And I hope you can easily understand after saw the image.
Copy link to clipboard
Copied
Have seen it 100 times. Explain the logic. Or do you always have only eight layers arranged this way? This is not from left to right, but some kind of сикось-накось (google could not translate : ).
Copy link to clipboard
Copied
Thanks r-bin I have modify and Now is working perfect. Thanku so much r-bin
Copy link to clipboard
Copied
Hello Eveyone, This script is perfect working, It is select Bottom to Top Layer.
But I want to Select Top to Bottom in Selected Layer in PS Script
Here is script , Please modify the script ?
Thanks in Advance
Copy link to clipboard
Copied
Have you tried reversing the order you process layer ID?
//for each id in the list
for (var i = 0; i < ids.length; i++)
someting like:
for (var i = ids.length; i >= 0; i--)