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

Simple InDesign Script to create new layers

Community Beginner ,
Dec 03, 2024 Dec 03, 2024

Copy link to clipboard

Copied

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

Views

153

Translate

Translate

Report

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

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

Votes

Translate

Translate
Guru , 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);
}

Votes

Translate

Translate
Guru ,
Dec 03, 2024 Dec 03, 2024

Copy link to clipboard

Copied

app.activeDocument.layers.add({name:"EPub"});
app.activeDocument.layers.add({name:"TOC"});

Votes

Translate

Translate

Report

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
Guru ,
Dec 03, 2024 Dec 03, 2024

Copy link to clipboard

Copied

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);
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thank you

Votes

Translate

Translate

Report

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