Highlighted

Rename Selected Layers problem...

Explorer ,
Sep 08, 2020

Copy link to clipboard

Copied

below script working good for rename selected layers. but when there is clipping mask layers then clipping mask layers also renamed automatically. 

so i want to rename  selected layers except clipping mask

 

 

 

var newName =("layer name", "Auto_bmd");

var layers = getSelectedLayers();
for (var i = 0; i < layers.length; i ++){
	layers[i].name = newName;
}


//get the list of multiple selected layers
photoshop%CA%A3%BF%F4%A5%BB%A5%EC%A5%AF%A5%C8

function getSelectedLayers(){ 
	var idGrp = stringIDToTypeID( "groupLayersEvent" );
	var descGrp = new ActionDescriptor();
	var refGrp = new ActionReference();
	refGrp.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Trgt" ));
	descGrp.putReference(charIDToTypeID( "null" ), refGrp );
	executeAction( idGrp, descGrp, DialogModes.ALL );
	var resultLayers=new Array();
	for (var ix=0;ix<app.activeDocument.activeLayer.layers.length;ix++){resultLayers.push(app.activeDocument.activeLayer.layers[ix])}
	var id8 = charIDToTypeID( "slct" );
    var desc5 = new ActionDescriptor();
    var id9 = charIDToTypeID( "null" );
    var ref2 = new ActionReference();
    var id10 = charIDToTypeID( "HstS" );
    var id11 = charIDToTypeID( "Ordn" );
    var id12 = charIDToTypeID( "Prvs" );  
    ref2.putEnumerated( id10, id11, id12 );
	desc5.putReference( id9, ref2 );
	executeAction( id8, desc5, DialogModes.NO );
	return resultLayers;
}

 

 Screenshot 2020-09-08 at 10.30.41 PM.png

 

@Kukurykus

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
I can suggest another option.
var nm = "NewName";

var selected = get_selected_layers_id();

for (var i = 0; i < selected.length; i++)
    {
    select_layer(selected[i]);
    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 = new Array();

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

Topics

Actions and scripting, How to

Views

64

Likes

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

Rename Selected Layers problem...

Explorer ,
Sep 08, 2020

Copy link to clipboard

Copied

below script working good for rename selected layers. but when there is clipping mask layers then clipping mask layers also renamed automatically. 

so i want to rename  selected layers except clipping mask

 

 

 

var newName =("layer name", "Auto_bmd");

var layers = getSelectedLayers();
for (var i = 0; i < layers.length; i ++){
	layers[i].name = newName;
}


//get the list of multiple selected layers
photoshop%CA%A3%BF%F4%A5%BB%A5%EC%A5%AF%A5%C8

function getSelectedLayers(){ 
	var idGrp = stringIDToTypeID( "groupLayersEvent" );
	var descGrp = new ActionDescriptor();
	var refGrp = new ActionReference();
	refGrp.putEnumerated(charIDToTypeID( "Lyr " ),charIDToTypeID( "Ordn" ),charIDToTypeID( "Trgt" ));
	descGrp.putReference(charIDToTypeID( "null" ), refGrp );
	executeAction( idGrp, descGrp, DialogModes.ALL );
	var resultLayers=new Array();
	for (var ix=0;ix<app.activeDocument.activeLayer.layers.length;ix++){resultLayers.push(app.activeDocument.activeLayer.layers[ix])}
	var id8 = charIDToTypeID( "slct" );
    var desc5 = new ActionDescriptor();
    var id9 = charIDToTypeID( "null" );
    var ref2 = new ActionReference();
    var id10 = charIDToTypeID( "HstS" );
    var id11 = charIDToTypeID( "Ordn" );
    var id12 = charIDToTypeID( "Prvs" );  
    ref2.putEnumerated( id10, id11, id12 );
	desc5.putReference( id9, ref2 );
	executeAction( id8, desc5, DialogModes.NO );
	return resultLayers;
}

 

 Screenshot 2020-09-08 at 10.30.41 PM.png

 

@Kukurykus

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional
I can suggest another option.
var nm = "NewName";

var selected = get_selected_layers_id();

for (var i = 0; i < selected.length; i++)
    {
    select_layer(selected[i]);
    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 = new Array();

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

Topics

Actions and scripting, How to

Views

65

Likes

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
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

The getSelectedLayers() function does not work correctly in this case, when all clipped layers are selected.
Plus it will mess things up if not all clipped layers are selected.
Need another function.
 

Likes

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
Reply
Loading...
Explorer ,
Sep 08, 2020

Copy link to clipboard

Copied

ok. can anybody provide me function for same.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Sep 08, 2020

Copy link to clipboard

Copied

I can suggest another option.
var nm = "NewName";

var selected = get_selected_layers_id();

for (var i = 0; i < selected.length; i++)
    {
    select_layer(selected[i]);
    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 = new Array();

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

Likes

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
Reply
Loading...
Explorer ,
Sep 08, 2020

Copy link to clipboard

Copied

thank you so much sir... its working

 

please help me for another problem

https://community.adobe.com/t5/photoshop/auto-clipping-mask-problem/m-p/11418869?page=1

Likes

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