Copy link to clipboard
Copied
Good morning friends! How do I delete the current name of the active layer when replacing with the name entered in the text field of the dialog box? What is missing, where am I going wrong?
#target photoshop
var doc = activeDocument;
app.preferences.rulerUnits = Units.CM;
function layerNamer() {
var opts = new Object();
win=new Window("dialog","Replace Layer Name",[0,0,300,100],{resizeable:true,});
text01=win.add("statictext",[20,30,110,50] ,"Type something:")
text02=win.add("edittext",[110,30,250,50] ,"")
but_1=win.add("button",[110,58,197,78],"Replace Layer Name");
but_1.onClick = function() {
opts.replace = text02.text;
processDoc(opts);
}
win.center();
win.show();
};
if ( app.documents.length > 0) { layerNamer(); }
function processDoc(opts) {
var find;
if ( opts.global && !opts.ignore ) { find = new RegExp(opts.find,'gi'); }
if ( !opts.global && !opts.ignore ) { find = new RegExp(opts.find,'i'); }
var doc = app.activeDocument;
recurseLayers(doc.layers);
function recurseLayers(layObj) {
for ( var i = 0; i < layObj.length; i++ ) {
if ( find.test(layObj.name) )
{
if (layObj.kind == LayerKind.TEXT && !opts.txtLay) { continue; }
layObj.name = layObj.name.replace(find,opts.replace);
}
if ( layObj.typename == 'LayerSet' )
{ recurseLayers(layObj.layers); }
}
}
};
If that's the case, just try this:
...#target photoshop
var doc = activeDocument;
app.preferences.rulerUnits = Units.CM;
if ( app.documents.length > 0) { layerNamer(); }
function layerNamer() {
win=new Window("dialog","Replace Layer Name",[0,0,300,100],{resizeable:true,});
text01=win.add("statictext",[20,30,110,50] ,"Type something:")
text02=win.add("edittext",[110,30,250,50] ,"")
but_1=win.add("button",[110,58,197,78],"Replace Layer Name");
but_1.onClick = function() {
try{
app.activeDocument.acti
Copy link to clipboard
Copied
What exactly are you trying to do? Normally you just specify a new name for the layer:
app.activeDocument.activeLayer.name = 'My new layer name'
Copy link to clipboard
Copied
What exactly am I trying to do? I need to rename the layer name through the "edittext" field of the dialog. This script I posted only adds the new name to the name and does not remove the original name.
Ideally, it should look like image 3
Copy link to clipboard
Copied
Well, the reason I ask what exactly are you doing is that your script seems overly complicated to just replace the layer name. If you script worked as you say you want it to work, it would replace all the layer names with the same thing, as you are looping the script with a recursive function. Do you want ALL layers to have the same name?
Copy link to clipboard
Copied
This script found right here in the adobe community! It is to rename only the selected layer nothing more, you have complete freedom to clean what is unnecessary, as long as it reaches the desired object. Thank you for your help!
Copy link to clipboard
Copied
If that's the case, just try this:
#target photoshop
var doc = activeDocument;
app.preferences.rulerUnits = Units.CM;
if ( app.documents.length > 0) { layerNamer(); }
function layerNamer() {
win=new Window("dialog","Replace Layer Name",[0,0,300,100],{resizeable:true,});
text01=win.add("statictext",[20,30,110,50] ,"Type something:")
text02=win.add("edittext",[110,30,250,50] ,"")
but_1=win.add("button",[110,58,197,78],"Replace Layer Name");
but_1.onClick = function() {
try{
app.activeDocument.activeLayer.name = text02.text;
}
catch(e){alert(e)}
win.close();
}
win.center();
win.show();
};
Copy link to clipboard
Copied
That's right, perfect! Thank you so much Chuck Uebele When I grow up, I want to be like you.
Copy link to clipboard
Copied
Ps-Design wrote
That's right, perfect! Thank you so much https://forums.adobe.com/people/Chuck+Uebele When I grow up, I want to be like you.
I've seen pictures of the "early Chuck", in social media, so cool that I'd like to be like him as a young man too, LOL.
(a bit of frivolousness never hurts )
Copy link to clipboard
Copied
My life is/was not that glamorous, lol.
Copy link to clipboard
Copied
That script of original poster is most complex I ever seen - to change name of actively set layer! - too bad that can't work.