1

I have an InDesign document with ~550 pages. On an every page, there are 4 frames, all the pages look the same (see image below). I'm using InDesign CS6 and JS.

I need a script that fulfills some rather basic functions, if possible:

1.

  • Target text frame (1)
  • Delete the text frame

2.

  • Target text frame (2)
  • Applying a given paragraph style

3.

  • Target image frame (4)
  • Fit Frame Proportionally
  • Do so on all pages

layout

I tried the following (see below). Somehow, ID tells me "myParagraph.applyParagraphStyle" and "myFrame.fit" is "not a function".

2.

var myDocument = app.activeDocument;
myParagraph = myDocument.pages.item(1);
myParagraphStyle  = myDocument.paragraphStyles.item('datum');
myParagraph.applyParagraphStyle(myParagraphStyle,true);

3.

var myDocument = app.activeDocument;
var myGraphic = myDocument.pages.item(3);
var myFrame = myGraphic.parent;
myFrame.fit(FitOptions.proportionally);

1 Answer 1

2

You need to look at the DOM for InDesign. Have a look here:

http://jongware.mit.edu/idcs6js/

myParagraph = myDocument.pages.item(1);

Paragraphs are not child nodes of pages. Also, I would address one page at the time and loop through pages.

Try:

var myParagraph = myDocument.pages[0].textFrames[0].paragraphs[0];

Similar problem with graphics. You need to address the container which is graphic parent and then graphic it contains:

var myGraphic = myDocument.pages[0].rectangles[0].graphics[0];

or

var myGraphic = myDocument.pages[0].allGraphics[0].graphics[0];

Alternatively, you can use pageItems, instead of textFrames or rectangles

4
  • Could you do me a favor? Just show me how this loop through the pages must look like, since I'm new to scripting and it will take me two hours to make it work.
    – VHS
    Aug 9, 2019 at 14:08
  • Referencing page items via their index is unreliable - it doesn't necessarily guarantee that you'll be targeting the correct page item. To reference the correct page item(s) consider utilizing the geometricBounds property instead - For instance you can infer the correct page item by checking whether its y1 and x1 coordinates are within a given range.
    – RobC
    Aug 9, 2019 at 14:42
  • In this case it worked since every page looked the same. But could you give me an example how your solution works?
    – VHS
    Aug 18, 2019 at 12:35
  • @VHS - Here is an gist of processing each text frame and doing something with it (such as deleting it) based on its y1 and x1 coordinates. It entails 1. Looping over each page in the document. 2. Processing each text frame found on each page via the custom handleTextFrames function. 3. In the body of the handleTextFrames function we obtain the text frames page geometry and conditionally do stuff (e.g. delete it) based on it's x1 and y1 coordinate. BTW. When writing a comment to someone you should @<name> them otherwise they aren't notified.
    – RobC
    Aug 21, 2019 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.