Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple InDesign Script to create new layers

Community Beginner ,
Dec 03, 2024 Dec 03, 2024

Hi all,

 

I'm trying to learn InDesign JavaScripting and I want to run a script in each active document to add two new layers to the bottom of the document.

 

I've surfed the internet but I can't find anything that makes sense to me, any help would be much appreciated.

 

This is what I have so far, this is saved as a .js file in my scripts folder;

 

var myDoc = app.activeDocument.Layer.add({name:"EPub"});
app.activeDocument.Layer.add({name:"TOC"});

 

It runs and the following error appears, what am I doing wrong?

 

Screenshot 2024-12-03 at 08.06.49.png

 

TOPICS
EPUB , How to , Scripting
490
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Valorous Hero , Dec 03, 2024 Dec 03, 2024
app.activeDocument.layers.add({name:"EPub"});
app.activeDocument.layers.add({name:"TOC"});
Translate
Valorous Hero , Dec 03, 2024 Dec 03, 2024

To move the layers to the bottom, use the move command, like so:

main();

function main() {
	var doc = app.activeDocument;
	var layerEPub = doc.layers.add({name:"EPub"});
	layerEPub.move(LocationOptions.AT_END);
	var layerTOC = doc.layers.add({name:"TOC"});
	layerTOC.move(LocationOptions.AT_END);
}
Translate
Valorous Hero ,
Dec 03, 2024 Dec 03, 2024
app.activeDocument.layers.add({name:"EPub"});
app.activeDocument.layers.add({name:"TOC"});
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 03, 2024 Dec 03, 2024

To move the layers to the bottom, use the move command, like so:

main();

function main() {
	var doc = app.activeDocument;
	var layerEPub = doc.layers.add({name:"EPub"});
	layerEPub.move(LocationOptions.AT_END);
	var layerTOC = doc.layers.add({name:"TOC"});
	layerTOC.move(LocationOptions.AT_END);
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2024 Dec 03, 2024
LATEST

Thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines