0

I have a parent page that contains 4 text frames. The first and last contain the book name and page number, respectively. I want to keep these as they are.

The two text frames in the middle of each page are placeholders, and I want these to be labelled, sequentially, "Question 1", "Question 2", "Question 3", etc.

E.g. Page 1 --> Question 1 | Question 2, Page 2 --> Question 3 | Question 4, Page 3 --> Question 5 | Question 6

I have been fiddling with chatgpt trying to figure this out but I the result is not quite right.

This is what I have so far, and it only adds the label to one box and not the other:

var myDocument = app.activeDocument;

// Loop through each page
for (var i = 0; i < myDocument.pages.length; i++) {
    var page = myDocument.pages.item(i);

    // Override master page items and update text frames
    for (var j = 0; j < page.masterPageItems.length; j++) {
        var masterItem = page.masterPageItems[j];
        if (masterItem instanceof TextFrame) {
            var overriddenItem = masterItem.override(page);

            // Calculate Question numbers for this page (only for the 2nd and 3rd text frames)
            if (j === 1 || j === 2) {
                var questionNumber = i * 2 + j;
                overriddenItem.contents = "Question" + questionNumber;
            }
        }
    }
}
1
  • Are you sure masterPageItems[1] and masterPageItems[2] are the correct master page items for these two text frames? Jan 3 at 19:52

0

Your Answer

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