• 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 Text Layer Ignore ?

Explorer ,
May 25, 2023 May 25, 2023

Copy link to clipboard

Copied

I am using photoshop cc 2021, what should I modify in the below script so that the text layer is not renamed

 

var nm = "New Name";
var selected = get_selected_layers_id();

if (selected.length > 1) {
    for (var i = 0; i < selected.length; i++) {
        var layerId = selected[i];
        var layerType = get_layer_type(layerId);

        if (layerType !== 'textLayer' && !is_clipping_mask(layerId)) {
            select_layer(layerId);
            app.activeDocument.activeLayer.name = nm;
        }
    }
} else if (selected.length === 1) {
    var layerId = selected[0];
    select_layer(layerId);
    app.activeDocument.activeLayer.name = nm;
}

select_layers(selected);

//////////////////////////////////////////////////////////////
function select_layer(id) {
    try {
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), id);

        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r);
        d.putBoolean(stringIDToTypeID("makeVisible"), false);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function select_layers(ids) {
    try {
        var r = new ActionReference();
        for (var i = 0; i < ids.length; i++) r.putIdentifier(stringIDToTypeID("layer"), ids[i]);

        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r);
        d.putBoolean(stringIDToTypeID("makeVisible"), false);

        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function get_selected_layers_id() {
    try {
        var selected = [];

        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayersIDs"));
        r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

        var list = executeActionGet(r).getList(stringIDToTypeID("targetLayersIDs"));

        for (var i = 0; i < list.count; i++) {
            selected.push(list.getReference(i).getIdentifier());
        }

        return selected;
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function get_layer_type(id) {
    try {
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), id);

        var desc = executeActionGet(r);
        var layerType = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID("layerSection")));

        return layerType;
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function is_clipping_mask(id) {
    try {
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), id);

        var desc = executeActionGet(r);
        var isClip = desc.getBoolean(stringIDToTypeID("group"));

        return isClip;
    } catch (e) {
        throw(e);
    }
}

 

 

TOPICS
Windows

Views

422

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
Adobe
Community Expert ,
May 26, 2023 May 26, 2023

Copy link to clipboard

Copied

What text layer?

 

A sample layered PSD file, or at least a cropped screenshot of the selected layer panel would be helpful to illustrate.

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
Explorer ,
May 27, 2023 May 27, 2023

Copy link to clipboard

Copied

Thanks to Reply.... I want that, if there is text layers or Clippingmask layer in the selected layers then text and Clippingmask layer should be ignored at the time of rename. but iam finally done &  modify this script 

var nm = "new name";
var selected = get_selected_layers_id();

if (selected.length > 1) {
    for (var i = 0; i < selected.length; i++) {
        var layerId = selected[i];
        var layerType = get_layer_type(layerId);

        if (layerType !== 'textLayer' && !is_clipping_mask(layerId)) {
            select_layer(layerId);
            var layer = app.activeDocument.activeLayer;

            // Check if the layer is a text layer
            if (layer.kind !== LayerKind.TEXT) {
                layer.name = nm;
            }
        }
    }
} else if (selected.length === 1) {
    var layerId = selected[0];
    select_layer(layerId);
    var layer = app.activeDocument.activeLayer;

    // Check if the layer is a text layer
    if (layer.kind !== LayerKind.TEXT) {
        layer.name = nm;
    }
}

select_layers(selected);

//////////////////////////////////////////////////////////////
function select_layer(id) {
    try {
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), id);

        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r);
        d.putBoolean(stringIDToTypeID("makeVisible"), false);
        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function select_layers(ids) {
    try {
        var r = new ActionReference();
        for (var i = 0; i < ids.length; i++) r.putIdentifier(stringIDToTypeID("layer"), ids[i]);

        var d = new ActionDescriptor();
        d.putReference(stringIDToTypeID("null"), r);
        d.putBoolean(stringIDToTypeID("makeVisible"), false);

        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function get_selected_layers_id() {
    try {
        var selected = [];

        var r = new ActionReference();
        r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("targetLayersIDs"));
        r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

        var list = executeActionGet(r).getList(stringIDToTypeID("targetLayersIDs"));

        for (var i = 0; i < list.count; i++) {
            selected.push(list.getReference(i).getIdentifier());
        }

        return selected;
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function get_layer_type(id) {
    try {
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), id);

        var desc = executeActionGet(r);
        var layerType = typeIDToStringID(desc.getEnumerationValue(stringIDToTypeID("layerSection")));

        return layerType;
    } catch (e) {
        throw(e);
    }
}

//////////////////////////////////////////////////////////////
function is_clipping_mask(id) {
    try {
        var r = new ActionReference();
        r.putIdentifier(stringIDToTypeID("layer"), id);

        var desc = executeActionGet(r);
        var isClip = desc.getBoolean(stringIDToTypeID("group"));

        return isClip;
    } catch (e) {
        throw(e);
    }
}

sample.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
Explorer ,
May 27, 2023 May 27, 2023

Copy link to clipboard

Copied

LATEST

please view this post & Modify to code 

Whatever document is open after the source document is closed, paste the selected layers in that document by whatever name it may be by any number.
modify this code

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-layer-duplicate-to-active-docu...

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