Duplicate and rename layers
- This topic has 5 replies, 3 voices, and was last updated 6 years, 6 months ago by .
- You must be logged in to reply to this topic.
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Duplicate and rename layers
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Duplicate and rename layers
I’m working on a script to duplicate a layer in all documents in a book. The script compiles all layers which are common across all documents, then allows the user to select the ones to duplicate. How can I within the script rename the layer copy at the same time?
Here’s the snippet:
//if the box is checked
if (checkList[check].checkedState == true)
{
//duplicate checked layer
docList[d].layers.item (layerList[check]).duplicate()
//How do I rename the layer which was created?
//does not work: docList[d].layers.previousItem (layerList[check]).name = “Unpriced”;
}
Any pointers?
Sorry if this is super basic, I’ve jsut started.
I’m not sure at a glance why the previousItem method isn’t working, but if you assign the duplicate layer to a variable:
var newLayer = docList[d].layers.item (layerList[check]).duplicate();
You can then refer to it later:
newLayer.name = "Unpriced";
That does it fine….
Thanks Mike!
Klaas, you can also rename it while duplicating:
docList[d].layers.item (layerList[check]).duplicate().name = "Unpriced";
Didn’t have a look at it, but I assume, that previousItem() needs a layer and not a number.
… or the index is messed up at this time.
OK, thanks for the help, all questions answered!
KvT
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies allows us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.
You have to be logged in to save.
Not a member? Join Today - it's FREE!