Skip to main content
Participating Frequently
February 15, 2009
Question

[CS3 JS] Help with script that batch turns layers on and off

  • February 15, 2009
  • 10 replies
  • 1498 views
Hi
I was wondering if there is a java script out there that will turn a layer on or off.
I need to batch turn a certain layer off. We deal a lot with answers keys etc in our books.
The real key is being able to batch this process.

Thanks
This topic has been closed for replies.

10 replies

himtyrantAuthor
Participating Frequently
February 16, 2009
I get what you are saying but how would that look as a java script?
Inspiring
February 16, 2009
It's fairly straightforward. Use the findText feature to find all instance of text in the character style and then (assuming that all such instances are in their own text frames), set the itemLayer of the text frames to the answer layer.

Dave
himtyrantAuthor
Participating Frequently
February 15, 2009
yeah it worked.
So I was wondering one more thing. The "answer" layers have a specific type of character style on them that is unique to that layer. Is there anyway to run a script that tell indesign to always move a text box with "answer" character style to the "answer" layer?
I would have no idea where to start in terms of the code for that.
Participant
September 6, 2013

It didn't work for me. I'm using INDD CS6

I know this is a very simple script, and that the turn on/turn off layer part of the script works perfectly fine (on individuall pages), but for some reason I can't get it to batch process.

I have a multi-version set of files with layers such as "de" for germany, "us" for United States, etc. that I need to batch turn on so that I can print.

Here is what I have:

var myFolder = Folder.selectDialog("Select Indesign Folder");

var myIndsnFiles = myFolder.getFiles("*.indd");

for(k=0; k<myIndsnFiles.length; k++)

{

   var myIndsnFiles = app.open(myIndsnFiles);

   

var myIndsnFiles = app.documents[0];

var answersLayer = myIndsnFiles.layers.item("us");

answersLayer.visible = false;

    app.activeDocument.close(SaveOptions.yes);

    }

Inspiring
February 15, 2009
As long as it works -- I didn't actually test it. But I think so.

Dave
himtyrantAuthor
Participating Frequently
February 15, 2009
Thank you thank you thank you.
So can I use this code for any time i need to open, do something then close and save?
Inspiring
February 15, 2009
You started just fine, but the leap from myFolderContents to myDocument leaves out a few steps. You need to open each document and process it. So you need a loop:

for (var j = 0; myFolderContents.length > j; j++) {
var myDocument = app.open(myFolderContents);
// the rest of your code goes here
}

Now, the only problem you might run into is if the opening of any of these documents throws up a fonts or links issue. Up to you whether you want that to happen or not. If not, you need to manage the interaction level. I'd do this:

for (var j = 0; myFolderContents.length > j; j++) {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
var myDocument = app.open(myFolderContents);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
// the rest of your code goes here
}

I know this looks a bit inefficient, but my sense is that you should have neverInteract active for as short a time as possible.

Dave
himtyrantAuthor
Participating Frequently
February 15, 2009
Here is what I have done.

I am not great at scripting

var myFileLocation = Folder.selectDialog("Please select path to files");
myFolder = new Folder ([myFileLocation]);
myFolderContents = myFolder.getFiles("*.indd"); // array
var myDocument = app.documents[0];
var answersLayer = myDocument.layers.item("answers");
answersLayer.visible = false;
app.activeDocument.close(SaveOptions.yes);
Inspiring
February 15, 2009
To do that, you have to open each document, switch off the layer and then save it again. How far did you get with this? Show us some code and we'll talk you through the process.

Dave
himtyrantAuthor
Participating Frequently
February 15, 2009
Sorry, I mean a group of .indd files within a specific folder.
So say I have a folder titled "Layout"
I want to select that folder and have all of the .indd files in that folder have the layer "Answers" turned off.

Does that make sense?

I tried to do this myself but have had no luck.
Inspiring
February 15, 2009
In this context, what is a batch?

Dave