Hi all, It's been a while since I last visited (and I'm getting older) so I forgot some of the basics and would appreciate some help.
I want to write a simple script that duplicates a layer into four layers with addendums to the layer name.
Example:
existing layer is named ABC
I would like to end up with four layers with the same contents but named
ABC-A
ABC-B
ABC-C
ABC-D
It seems this will require a script instead of an action because I will need to use the original name as part of the new layer names and I can't use variables or cut/paste in actions.
I hope this made sense, and I hope it is as simple as it seems. I am happy to pay for the help.
Thanks so much,
Ed
Need help with simple script to duplicate layers
Need help with simple script to duplicate layers
Bonjour
Is this appropriate?
Code: Select allapp.preferences.rulerUnits = Units.PIXELS;
app.displayDialogs = DialogModes.NO;
docRef = app.activeDocument;
//alert(docRef.activeLayer.name)
var NomCalc = docRef.activeLayer.name;
var extName = new Array( "A", "B", "C", "D");
docRef.selection.selectAll();
//docRef.selection.copy();
try
{
docRef.selection.copy();
catreCalc();
}
catch(e) { alert("calque vide"); docRef.selection.deselect(); };
function catreCalc()
{
try
{
for(i=0; i<4; i++)
{
docRef.paste();
docRef.activeLayer.name = NomCalc + "." + extName;
}
}
catch(e){};
}
Is this appropriate?
Code: Select allapp.preferences.rulerUnits = Units.PIXELS;
app.displayDialogs = DialogModes.NO;
docRef = app.activeDocument;
//alert(docRef.activeLayer.name)
var NomCalc = docRef.activeLayer.name;
var extName = new Array( "A", "B", "C", "D");
docRef.selection.selectAll();
//docRef.selection.copy();
try
{
docRef.selection.copy();
catreCalc();
}
catch(e) { alert("calque vide"); docRef.selection.deselect(); };
function catreCalc()
{
try
{
for(i=0; i<4; i++)
{
docRef.paste();
docRef.activeLayer.name = NomCalc + "." + extName;
}
}
catch(e){};
}
Need help with simple script to duplicate layers
The only thing about copy/paste is that if you have a layer with transparency, paste will always put the content of the layer in the center of the document.
I would go with Layer Via Copy command:
Code: Select allapp.preferences.rulerUnits = Units.PIXELS;
app.displayDialogs = DialogModes.NO;
docRef = app.activeDocument;
var layerRef = docRef.activeLayer
var extName = new Array( "A", "B", "C", "D");
for(i=0; i<4; i++)
{
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
docRef.activeLayer.name = layerRef.name + "-" + extName;
}
layerRef.remove()
I would go with Layer Via Copy command:
Code: Select allapp.preferences.rulerUnits = Units.PIXELS;
app.displayDialogs = DialogModes.NO;
docRef = app.activeDocument;
var layerRef = docRef.activeLayer
var extName = new Array( "A", "B", "C", "D");
for(i=0; i<4; i++)
{
executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
docRef.activeLayer.name = layerRef.name + "-" + extName;
}
layerRef.remove()
Need help with simple script to duplicate layers
Wow, that was fast ... thank you so much txuku and tyr, it works great.
There is just one little tweak. I used TYR's script, but it leaves 5 layers - the 4 new renamed layers and the original layer.
I would like to have just the 4 renamed layers.
I tried to figure out how to do it myself by just renaming the first layer first and changing the loop to 3 for the additional layers.
But as you can tell by my writing this message ... I couldn't figure it out.
Any thoughts?
Mike, I made a donation to the site ... thanks for such a great site.
Ed
There is just one little tweak. I used TYR's script, but it leaves 5 layers - the 4 new renamed layers and the original layer.
I would like to have just the 4 renamed layers.
I tried to figure out how to do it myself by just renaming the first layer first and changing the loop to 3 for the additional layers.
But as you can tell by my writing this message ... I couldn't figure it out.
Any thoughts?
Mike, I made a donation to the site ... thanks for such a great site.
Ed
Need help with simple script to duplicate layers
aboyne wrote:There is just one little tweak. I used TYR's script, but it leaves 5 layers - the 4 new renamed layers and the original layer.
I would like to have just the 4 renamed layers.
That's weird!
I'm referencing the active layer in the beginning and then removing it in the end:
Code: Select allvar layerRef = docRef.activeLayer
[...]
layerRef.remove()
Are you sure you're using my script?
Here's my result:
I would like to have just the 4 renamed layers.
That's weird!
I'm referencing the active layer in the beginning and then removing it in the end:
Code: Select allvar layerRef = docRef.activeLayer
[...]
layerRef.remove()
Are you sure you're using my script?
Here's my result:
Need help with simple script to duplicate layers
I am so sorry. I didn't grab that last line.
It works perfectly now. Thank you so much.
It works perfectly now. Thank you so much.