Copy link to clipboard
Copied
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:
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:
Copy link to clipboard
Copied
AFAIK, in IDS you can't use Clipboard - copy / cut / paste - but location as (x, y) should work perfectly fine.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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();
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
You have to describe in more detail your "similar solution".
Copy link to clipboard
Copied
Hi Robert,
I used the same method to generate the index (and it was automatically placed on the first page of the document).
I wasn't aware of the index.textContainer way to find the index so I loopet through all the styries in the document to find the INDEX.STORY
Then I used the same method as in Peters example above to move the content to the target text frame.
After that I removed the empty text frame on the first page.
So it worked. But I then discovered that the moved index was not possible to utdate automatically as it was no longer the actual index story. Just a regular story with the same content as the original.
So this is how I solved it instead:
Copy link to clipboard
Copied
You don't have to actually move anything - just link it / thread with the destination TextFrame...
index.textContainers[0] is just a normal way to get 1st TextFrame of the Story - generated index is just a Story.
Copy link to clipboard
Copied
OK, here is a "crazy" idea - as what you get when you generate Index - is a Story - then if you thread TO IT - so use NextTextFrame - and then "clean up" - delete TF created for the first time when creating index for the first time - your destination TextFrame AND Index Story will remain intact - and you can then call index.update() instead of index.generate() ?
I hope I'm clear.
Copy link to clipboard
Copied
Crystal clear 🙂 !
And how do they use to say? "There is more than one way to skin a cat"?
Copy link to clipboard
Copied
Exactly.
If you like any of the replies - you could mark them as "correct answer".
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.)
Copy link to clipboard
Copied
That's the trick, indeed!
Thx Peter.