Copy link to clipboard
Copied
I have this tiny script to rename a Sub-layer which works the first time I use it, then it adds to the existing sub-layer name when I run it after the first time.
var docRef = activeDocument; | |
var sel = docRef.selection; | |
for (var i=0; i < sel.length; i++) | |
sel.name = "CUTTER_B" + sel.name; |
Any way to get this to consistently rename the sub-layer?
Copy link to clipboard
Copied
Hi PrepressPro1
your code only works with page items - not with sublayers.
Unfortunately you didn't answer one month ago.
"… is this "sublayer" really a sublayer? Or a grouped item instead? …"
Same question again.
For selected page items you can do something like this
var docRef = activeDocument;
var sel = docRef.selection;
for (var i=0; i < sel.length; i++) {
var nme = sel.name.replace("CUTTER_B","");
sel.name = "CUTTER_B" + nme;
}
Have fun
Copy link to clipboard
Copied
It is an object on a sub-layer. Sorry for the hiatus in my posting. Projects get back burnered with the press of production work. Thank you for your reply.
Copy link to clipboard
Copied
Here is the sub-layer before running the scrip with the object selected.
After the script is run.
It still adds the name instead of replacing the name.
Copy link to clipboard
Copied
That makes no difference. Same procedere as for page items
var docRef = activeDocument;
var sel = docRef.activeLayer;
//var sel = docRef.selection;
//for (var i=0; i < sel.length; i++) {
//var nme = sel.name.replace("CUTTER_B","");
var nme = sel.name.replace("CUTTER_B","");
sel.name = "CUTTER_B" + nme;
//sel.name = "CUTTER_B" + nme;
//}
Have fun
Or if I understood you wrong: Would you replace the whole name with Cutter_B?
Then: sel.name = "CUTTER_B"