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