Copy link to clipboard
Copied
In this script working Only Background Layer Ignore. I wish How to Ignore Text Layer & PNG Layers.
Thanks in Advance Sir
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
// call the source document
var srcDoc = app.activeDocument;
var numOfLayers = srcDoc.layers.length;
var vCount = 0;
var hCount = 0;
// main loop
for (var i = numOfLayers -1; i >= 0 ; i--)
{
// get a referenec to each layer as we loop over them
var thisLayer = srcDoc.layers[i];
var artLayer= srcDoc.artLayers[i].visible=false;
// get the layer bounds of each layer as you go
srcDoc.activeLayer = thisLayer;
var lb = get_layer_bounds();
// set a variable to for portrait or landscape
var portrait = true;
// if layer is wider than it is long,
// it's landscape
if (lb[0] > lb[1]) portrait = false;
//alert(lb[0] + "," + lb[1] + "\n" + portrait + "\n" +thisLayer.name);
// ignore the background layer
// if there is one
var art=app.activeDocument.artLayer;
if (thisLayer.isBackgroundLayer==false)
{
if (portrait)
{
srcDoc.artLayers[i].name = "VFrame";
// add one to the horizontal count
hCount +=1
}
else
{
srcDoc.artLayers[i].name = "HFrame";
// add one to the vertical count
vCount+=1
}
}
}
//var docName = srcDoc.name.substring(0, srcDoc.name.length -4);
//var imgName = vCount + "v" + hCount + "h_" + docName + "_0001.psd";
//duplicateIt(imgName);
// Set Display Dialogs back to normal
displayDialogs = DialogModes.ALL; // NORMAL
// function GET LAYER BOUNDS ()
// ----------------------------------------------------------------
function get_layer_bounds()
{
var x = parseFloat(app.activeDocument.activeLayer.bounds[0]);
var y = parseFloat(app.activeDocument.activeLayer.bounds[1]);
var x1 = parseFloat(app.activeDocument.activeLayer.bounds[2]);
var y1 = parseFloat(app.activeDocument.activeLayer.bounds[3]);
var selW = parseFloat(x1-x);
var selH = parseFloat(y1-y);
// return the results as an array
return [selW, selH];
}
function duplicateIt(str)
{
// duplicate image into new document
if (arguments.length == 0) str = "temp";
var id428 = charIDToTypeID( "Dplc" );
var desc92 = new ActionDescriptor();
var id429 = charIDToTypeID( "null" );
var ref27 = new ActionReference();
var id430 = charIDToTypeID( "Dcmn" );
var id431 = charIDToTypeID( "Ordn" );
var id432 = charIDToTypeID( "Frst" );
ref27.putEnumerated( id430, id431, id432 );
desc92.putReference( id429, ref27 );
var id433 = charIDToTypeID( "Nm " );
desc92.putString( id433, str ); // name
executeAction( id428, desc92, DialogModes.NO );
}
As there is no official "PNG" layer kind, what do you personally consider a PNG layer?
Common layer kinds are mentioned here (edit, link updated):
if (thisLayer.isBackgroundLayer==false && layer.kind!=LayerKind.TEXT);
Copy link to clipboard
Copied
As there is no official "PNG" layer kind, what do you personally consider a PNG layer?
Common layer kinds are mentioned here (edit, link updated):
if (thisLayer.isBackgroundLayer==false && layer.kind!=LayerKind.TEXT);
Copy link to clipboard
Copied
Thanku very soo much , It's working fine..But one thing PNG Layer how to ignore in PS Scripts.
Again Thank in Advance
Copy link to clipboard
Copied
Glad the code for ignoring the text layer works, but you didn't answer my previous question...
As there is no official "PNG" layer kind, what do you personally consider a PNG layer?
Can you post a cropped screenshot of your layers panel? Can you post a link to a download file? Do you mean a PNG image placed as a smart object? What exactly do you mean?
Copy link to clipboard
Copied
I have one Template Many Vertical Frame Many Horizontal Frame & Many PNG Layer..I wish select Vertical Frame and Horizontal Frame not PNG Layer. I want to ignore PNG Layer in My Template.
In this script I run in PS.. Select the All Layer like vertical, horizontal,png etc..
Copy link to clipboard
Copied
Can you post a cropped screenshot of your layers panel? Can you post a link to a download file? Otherwise I can't attempt to help.
Copy link to clipboard
Copied
When I Script run it's taking PNG Layer. I wish ignore PNG Layer in My Script.
Thanks in Advance
Copy link to clipboard
Copied
So it appears that what you are calling a "PNG Layer" is a Smart Object layer.
As long as you are happy to globally ignore all SO layers, then give this a try:
if (thisLayer.isBackgroundLayer===false && layer.kind!=LayerKind.TEXT && layer.kind!=LayerKind.SMARTOBJECT);
P.S. If the layer name was static or used a consistent pattern, then it would also be possible to ignore the layer name/pattern using a regular expression.
Copy link to clipboard
Copied
Thanks That working ....
One Thing I can Select HFrame in My Template.
displayDialogs = DialogModes.NO; // OFF
var layer = app.activeDocument.activeLayer;
var layerName = layer.name;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//for (var i = 0; i < numOfLayers-1 ; i++)
//{
// get a referenec to each layer as we loop over them
//var thisLayer = srcDoc.layers[i];
if(layerName=="HFrame")
{
alert("H");
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "HFrame");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(21);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, DialogModes.NO);
//break;
}
else
{
alert("V");
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putName(cTID('Lyr '), "VFrame");
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('MkVs'), false);
var list1 = new ActionList();
list1.putInteger(21);
desc1.putList(cTID('LyrI'), list1);
executeAction(cTID('slct'), desc1, DialogModes.NO);
//break;
}
// }
I wish If Conditon is False ,How Can Do
Thanks in Advance
Copy link to clipboard
Copied
How to Reorder frames
Copy link to clipboard
Copied
@Nir Photo Art wrote:
This Script is all Layer Rename only Selected Layer Rename
Have you posted in the correct topic?
Copy link to clipboard
Copied
So to be clear, the original code works how you wish, it renames all layers except text and smart object layers.
Now you want to do similar, but for only selected layers that are not text or smart object layers?
Is that correct?
There are many examples of code in the forum to apply various processing steps to selected layers, I'd start with a search of the forum.
Copy link to clipboard
Copied
I'll take a look and see what I can do.
Copy link to clipboard
Copied
OK, try this code. I had to rewrite the script as it was taking me longer to troubleshoot the adapted code than to start again from scratch. If I have missed something in reworking the code, please let me know.
The script will rename only selected layers with portrait (VFrame) or landscape (HFrame) content, without renaming a selected Background image layer, selected text layers, selected smart object layers or selected adjustment layers. A single history stage undo has also been added.
/*
Rename Selected layers to HFrame or VFrame.jsx
v1.0 - 19th June 2022, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-ignore-text-layer-amp-png-layer-in-ps-scripts/td-p/11723306
*/
#target photoshop
// Layer bounds variables
var layerBounds = activeDocument.activeLayer.bounds;
var layerWidth = layerBounds[2].value - layerBounds[0].value;
var layerHeight = layerBounds[3].value - layerBounds[1].value;
function main() {
// Save the current dialog display settings
var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
// Get the selected layers: courtesy of jazz-y
var s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('targetLayersIDs'));
r.putEnumerated(s2t('document'), s2t('ordinal'), s2t('targetEnum'));
var lrs = executeActionGet(r).getList(p),
sel = new ActionReference();
// Loop over the selected layers: courtesy of jazz-y
for (var i = 0; i < lrs.count; i++) {
sel.putIdentifier(s2t('layer'), p = lrs.getReference(i).getIdentifier(s2t('layerID')));
(r = new ActionReference()).putIdentifier(s2t('layer'), p);
(d = new ActionDescriptor()).putReference(s2t("target"), r);
executeAction(s2t('select'), d, DialogModes.NO);
// Rename the selected layers
with (activeDocument.activeLayer) if (isBackgroundLayer === false && kind === LayerKind.NORMAL
&& kind !== LayerKind.TEXT && kind !== LayerKind.SMARTOBJECT) {
if (layerWidth > layerHeight) {
activeDocument.activeLayer.name = "HFrame";
} else {
activeDocument.activeLayer.name = "VFrame";
}
}
}
// Finish the loop
// Restore the dialogs
app.displayDialogs = savedDisplayDialogs;
}
// Single history stage undo
activeDocument.suspendHistory("Rename Selected layers to HFrame or VFrame.jsx", "main()");
Copy link to clipboard
Copied
@Nir Photo Art wrote:
when working in Photoshop CS 3, an error occurs. It is possible to solve this problem and this error
Photoshop CS3 Layer Rename .
Line : 19 var rs = executeAction Get ( r ) .getList ( p )
I can't test in such an old version of Photoshop.
All I can do is try some different code that works on selected layers, not knowing it it will help or not.
Copy link to clipboard
Copied
Try this alternative code version in CS3 to see if it avoids the previous error when processing selected layers:
/*
Rename Selected layers to HFrame or VFrame Alternative Code.jsx
v1.0 - 12th July 2022, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-ignore-text-layer-amp-png-layer-in-ps-scripts/td-p/11723306
Alternative code to process selected layers from:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/apply-an-action-to-all-selected-layers/td-p/8907701
*/
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
myDocument.suspendHistory("Rename Selected layers to HFrame or VFrame Alternative Code.jsx", "main(myDocument)");
}
// Layer bounds variables
var layerBounds = activeDocument.activeLayer.bounds;
var layerWidth = layerBounds[2].value - layerBounds[0].value;
var layerHeight = layerBounds[3].value - layerBounds[1].value;
function main() {
var theLayers = getSelectedLayersIdx();
// reselect layers;
for (var p = 0; p < theLayers.length; p++) {
selectLayerByIndex(theLayers[p], false);
// Rename the selected layers
with(activeDocument.activeLayer) if (isBackgroundLayer === false && kind === LayerKind.NORMAL &&
kind !== LayerKind.TEXT && kind !== LayerKind.SMARTOBJECT) {
if (layerWidth > layerHeight) {
activeDocument.activeLayer.name = "HFrame";
} else {
activeDocument.activeLayer.name = "VFrame";
}
}
}
}
// Functions
function selectLayerByIndex(index, add) {
add = undefined ? add = false : add;
var ref = new ActionReference();
ref.putIndex(charIDToTypeID("Lyr "), index);
var desc = new ActionDescriptor();
desc.putReference(charIDToTypeID("null"), ref);
if (add) desc.putEnumerated(stringIDToTypeID("selectionModifier"), stringIDToTypeID("selectionModifierType"), stringIDToTypeID("addToSelection"));
desc.putBoolean(charIDToTypeID("MkVs"), false);
try {
executeAction(charIDToTypeID("slct"), desc, DialogModes.NO);
} catch (e) {
alert(e.message);
}
}
function getSelectedLayersIdx() {
// by paul mr
var selectedLayers = new Array();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
if (desc.hasKey(stringIDToTypeID('targetLayers'))) {
desc = desc.getList(stringIDToTypeID('targetLayers'));
var c = desc.count;
var selectedLayers = new Array();
for (var i = 0; i < c; i++) {
try {
activeDocument.backgroundLayer;
selectedLayers.push(desc.getReference(i).getIndex());
} catch (e) {
selectedLayers.push(desc.getReference(i).getIndex() + 1);
}
}
} else {
var ref = new ActionReference();
ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("ItmI"));
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
try {
activeDocument.backgroundLayer;
selectedLayers.push(executeActionGet(ref).getInteger(charIDToTypeID("ItmI")) - 1);
} catch (e) {
selectedLayers.push(executeActionGet(ref).getInteger(charIDToTypeID("ItmI")));
}
}
return selectedLayers;
}