🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: adobe.scripting.indesign
11 messages
11 total messages Started by hmtyrant Sun, 15 Feb 2009 20:08
[CS3 JS] Help with script that batch turns layers on and off
#1206
Author: hmtyrant
Date: Sun, 15 Feb 2009 20:08
6 lines
883 bytes
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
Re: [CS3 JS] Help with script that batch turns layers on and off
#1208
Author: Dave_Saunders
Date: Sun, 15 Feb 2009 20:58
3 lines
738 bytes
In this context, what is a batch?

Dave
Re: [CS3 JS] Help with script that batch turns layers on and off
#1209
Author: hmtyrant
Date: Sun, 15 Feb 2009 21:18
7 lines
899 bytes
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.
Re: [CS3 JS] Help with script that batch turns layers on and off
#1210
Author: Dave_Saunders
Date: Sun, 15 Feb 2009 21:22
3 lines
797 bytes
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
Re: [CS3 JS] Help with script that batch turns layers on and off
#1211
Author: hmtyrant
Date: Sun, 15 Feb 2009 21:25
11 lines
1022 bytes
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);
Re: [CS3 JS] Help with script that batch turns layers on and off
#1212
Author: Dave_Saunders
Date: Sun, 15 Feb 2009 21:41
19 lines
1618 bytes
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[j]);
// 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[j]);
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
Re: [CS3 JS] Help with script that batch turns layers on and off
#1214
Author: hmtyrant
Date: Sun, 15 Feb 2009 21:54
2 lines
724 bytes
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?
Re: [CS3 JS] Help with script that batch turns layers on and off
#1215
Author: Dave_Saunders
Date: Sun, 15 Feb 2009 22:01
3 lines
685 bytes
As long as it works -- I didn't actually test it. But I think so.

Dave
Re: [CS3 JS] Help with script that batch turns layers on and off
#1216
Author: hmtyrant
Date: Sun, 15 Feb 2009 22:18
3 lines
969 bytes
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.
Re: [CS3 JS] Help with script that batch turns layers on and off
#1217
Author: Dave_Saunders
Date: Mon, 16 Feb 2009 00:21
3 lines
857 bytes
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
Re: [CS3 JS] Help with script that batch turns layers on and off
#1218
Author: hmtyrant
Date: Mon, 16 Feb 2009 02:39
1 lines
706 bytes
I get what you are saying but how would that look as a java script?
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads