Skip to main content
Known Participant
January 3, 2021
Answered

How to ignore Text Layer & PNG Layer in PS Scripts

  • January 3, 2021
  • 2 replies
  • 2119 views

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 );
}

This topic has been closed for replies.
Correct answer Stephen Marsh

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):

 

 
 
I'm not 100% sure if this is correct:
 
if (thisLayer.isBackgroundLayer==false && layer.kind!=LayerKind.TEXT);
 

2 replies

Stephen Marsh
Community Expert
Community Expert
June 19, 2022

@Nir Photo Art wrote:

 This Script is all Layer Rename only Selected Layer Rename



Have you posted in the correct topic?

Stephen Marsh
Community Expert
Community Expert
June 19, 2022

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.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
January 3, 2021

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):

 

 
 
I'm not 100% sure if this is correct:
 
if (thisLayer.isBackgroundLayer==false && layer.kind!=LayerKind.TEXT);
 
MXKSAuthor
Known Participant
January 4, 2021

Thanku very soo much , It's working fine..But one thing PNG Layer how to ignore in PS Scripts. 

 

Again Thank in Advance

Stephen Marsh
Community Expert
Community Expert
January 4, 2021

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?