• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to ignore Text Layer & PNG Layer in PS Scripts

Participant ,
Jan 03, 2021 Jan 03, 2021

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

TOPICS
Actions and scripting

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 03, 2021 Jan 03, 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);
 

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 03, 2021 Jan 03, 2021

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

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 03, 2021 Jan 03, 2021

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2021 Jan 03, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 03, 2021 Jan 03, 2021

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2021 Jan 03, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 03, 2021 Jan 03, 2021

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

sdd.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2021 Jan 04, 2021

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.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 05, 2021 Jan 05, 2021

Copy link to clipboard

Copied

Thanks That working ....

One Thing I can Select HFrame in My Template.

Capture.JPG

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 16, 2023 Sep 16, 2023

Copy link to clipboard

Copied

LATEST

How to Reorder frames 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2022 Jun 18, 2022

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2022 Jun 18, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2022 Jun 19, 2022

Copy link to clipboard

Copied

I'll take a look and see what I can do.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 19, 2022 Jun 19, 2022

Copy link to clipboard

Copied

 

@Nir Photo Art 

 

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()");

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 12, 2022 Jul 12, 2022

Copy link to clipboard

Copied

@Nir Photo Art 

 

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

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines