Duplicate a layer with a new Name
I am writing a script that duplicates all layers in a document, but adds a new name (In this case, it's the original layer name with the words Hat at the end of it).
My script is pasted below and works fine (It's based on another script I wrote).
I've just got a few questions:
1) I only want it to work on selected layers and not every layer in the document. How can I do this?
2) When the script is finished, it displyas the following error message:
Error 2: sourceDoc is undefined.
Line: 9
-> with(sourceDoc) {
I don't understand this error, could someone explain it. Thanks!
Here is my code:
var myDoc = app.activeDocument; // returns the document object
var myLayers = myDoc.layers;
//Go through all layers of source document and copy artwork
for (i = 0; i < myLayers.length; i++) {
myLayers.hasSelectedArtwork = true;
};
with(sourceDoc) {
var count = pageItems.length;
for (var i = 0; i < count; i++) {
pageItems.selected = true;
}
redraw();
copy();
for (var i = 0; i < count; i++) {
pageItems.selected = false;
}
var title = myLayers.name;
var title = title + "hat";
newLayer = myDoc.layers.add();
newLayer.name = title;
//Paste into this new layer
newLayer = app.paste();
}
