Skip to main content
Known Participant
November 1, 2023
Question

InDesign server adaptation of script

  • November 1, 2023
  • 14 replies
  • 862 views

Hi,

I'm working on several scripts to create an index based on all documents in a InDesign book.

So far my script works well:

  1. It creats and saves a new indesign document (index.indd) based on an exisiting template.
  2. It opens the Book file and add the document at the end of the book.
  3. It generates an Index based on all documents in the book.

 

I had a hard time figuring out how to place the index within the margins of the first page in the index document. When I used index.generate it ended up in a text frame with the geometricBounds [0,0]

 

Then I found out about the generate properties and used placePoint as "undefined". That created a text frame at the page top but within the left margin!

 

I decided to define the top margin:

var marginTopp=myDoc.pages[0].marginPreferences.top;
and changed the setting of the placePoint to [0,marginTopp]. It worked.
 
I use this solution to make sure the index ends up in the INDEX.STORY so it can be updates further on.
 
Now to my question...
Will this work on an InDesign server. I have managed to avoid anything that involves the UI (I think) but I'm concerned regarding the placePoint. If it's not good for a server what option do I have?

My regards
This topic is closed to new replies. Start a new post to keep the conversation going.

14 replies

Peter Kahrel
Community Expert
Community Expert
November 3, 2023

It's all much simpler, should have thought of it earlier. Create an object style, set the size and position (and whatever else) in the style. Then this two-liner is all you need:

 

 

index = app.documents[0].indexes[0].generate()[0];
index.textContainers[0].appliedObjectStyle = 
  app.documents[0].objectStyles.item('Index');

 

 

(You could actually do it in one line, but it'll be long & unreadable.)

Known Participant
November 3, 2023

That's the trick, indeed!
Thx Peter.

Peter Kahrel
Community Expert
Community Expert
November 3, 2023

It's more robust (in my opinion, anyway) because you don't have to work out where to place the frame, how to size it, set columns, etc. It's all determined by the frame on the master spread.

 

As for updating the index manually, that's easy to do:

 

- Delete the index story (leave the frames): Ctrl/Cmnd+A, Del.

- Generate the index, place it anywhere on the same page as the (now empty) first index frame.

- Thread the newly generated index frame to the first frame of the index story

- Delete the generated index frame.

Known Participant
November 3, 2023

Hi again Peter.
Then I get it. And I agree that you don't have to bother about creating the text frame and all eventual properties for it.
But as long as I only want a simple text frame it's simpler but not as robust as you suggest. I agree with that.
But one of the upsides with my approach is that I can update the index simply by using "Generate Index".  
So it's pro's and con's with both, I think.

Peter Kahrel
Community Expert
Community Expert
November 3, 2023

A simpler and more robust approach is to add a text frame for the index in your template and override it when you generate and place the index. Label the frame 'index' on the Layers panel, then after you override the frame, you do this (works in ID Server and ID Desktop):

 

 

// Find the target frame
target = app.documents[0].textFrames.item ('index');

// Generate the index. The function returns
// an array of stories
index = app.documents[0].indexes[0].generate()[0];

// Get a reference to the frame, need to remove it later
indexFrame = index.textContainers[0];

// Move the index story to the target frame
index.move (LocationOptions.AT_BEGINNING, target);

// Remove the frame that the index was generated in
indexFrame.remove();

 

Known Participant
November 3, 2023

Hi Peter,
Thanks for the comment. I did a solution similar to the above. In what way do you consider it more robust?
My challenge with the abow move solution was that the moved index wasn't possible to update later in a manual phase. What did I do wrong?

/Jan

Robert at ID-Tasker
Legend
November 3, 2023

You have to describe in more detail your "similar solution". 

 

Robert at ID-Tasker
Legend
November 1, 2023

AFAIK, in IDS you can't use Clipboard - copy / cut / paste - but location as (x, y) should work perfectly fine. 

 

Known Participant
November 2, 2023

Thanks Robert.
Then I will ask my ID Server Manager to try it out.
If you want I can post the result here together with the very basic script for Desktop run?
Tegards,
Jan