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

InDesign server adaptation of script

Explorer ,
Nov 01, 2023 Nov 01, 2023

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:

  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
TOPICS
Scripting

Views

327

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 Expert ,
Nov 01, 2023 Nov 01, 2023

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. 

 

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
Explorer ,
Nov 02, 2023 Nov 02, 2023

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

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 Expert ,
Nov 03, 2023 Nov 03, 2023

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

 

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
Explorer ,
Nov 03, 2023 Nov 03, 2023

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

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 Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

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

 

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
Explorer ,
Nov 03, 2023 Nov 03, 2023

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:

function generateIndex()//generates the index story
{
var myDoc=app.documents[0];
var marginTopp=myDoc.pages[0].marginPreferences.top;//Place the top of the index text frame at the top margin on page one
var myIndex = myDoc.indexes[0];
myIndex.generate
(
// [1] on page, spread or master spread
app.documents[0].pages[0] ,
 
// [2] placePoint
[0,marginTopp],
 
// [3] destinationLayer
undefined ,
 
// [4] autoflowing
true ,
 
// [5] includeOverset
true
);

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 Expert ,
Nov 03, 2023 Nov 03, 2023

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. 

 

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 Expert ,
Nov 03, 2023 Nov 03, 2023

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.

 

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
Explorer ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

Crystal clear 🙂 !
And how do they use to say? "There is more than one way to skin a cat"?

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 Expert ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

LATEST

Exactly.

 

If you like any of the replies - you could mark them as "correct answer".

 

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 Expert ,
Nov 03, 2023 Nov 03, 2023

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.

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
Explorer ,
Nov 03, 2023 Nov 03, 2023

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.

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 Expert ,
Nov 03, 2023 Nov 03, 2023

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.)

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
Explorer ,
Nov 03, 2023 Nov 03, 2023

Copy link to clipboard

Copied

That's the trick, indeed!
Thx Peter.

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