Correct use of dataMergeImagePlaceholders.add()
Hi All
I'm very new to InDesign and ExtendScript and also this forum so apologies in advance for any indiscretions.
I'm having trouble with one particular aspect of a script I've written to duplicate pages and add Data Merge text and image placeholders to page items in the new pages.
I have a template page with 6 rollover buttons each to display one of 6 photos.
The image frames are in buttons so I can use the 'show/hide buttons' action on rollover.
This works well.
The frames in the photo buttons are empty in the template and the buttons are named such that I can uniquely identify each button on each page.
There are also 3 empty uniquely named text frames on each page.
The code duplicates the template page a number of times according to the user's requirements.
After the pages are duplicated I go back to each page to find the empty text frames adding a data merge placeholder to each using dataMergeTextPlaceholders.add()
This works perfectly; so I know I'm iterating the pages correctly and applying the correct methodology in programmatically adding DataMergeFields (at least for text fields).
However when I try to do the same for the photos with image placeholders using dataMergeImagePlaceholders.add() it crashes InDesign (literally).
I suspect that the problem might be the image frame being part of a button, not a simple page item like the text frames.
So when I search for and find the named page item I'm getting the button not the image frame.
Here is the code I'm currently using (and failing) to find the button and add an image placeholder:
// image place holders
var imageFieldPrefix = ["Photo1 Ext", "Photo2 Ext", "Photo3 Ext", "Photo4 Ext", "Photo5 Ext", "Photo6 Ext"];
// suffix of this sheet
thisSuffix = ("0" + (cnt1+1)).slice (-2)
for (cnt2 = 0; cnt2 < imageFieldPrefix.length; cnt2++)
{
// construct the field name
fieldName = imageFieldPrefix[cnt2] + thisSuffix;
// find the graphic frame
newImageItem = currentPage.pageItems.itemByName(fieldName); // this returns button item
// add the data merge placeholder.
myDataMergeField = get_field(fieldName, myDocument); // this returns DataMergeField
var myFieldHolder = myDocument.dataMergeImagePlaceholders.add(newImageItem, myDataMergeField); // this brings down the lot
}
So my question is: Can anyone tell me what is the right argument to pass to dataMergeImagePlaceholders.add() and how to get it from my button?
(Or am I on the wrong track?)
Thanks in advance.
Michael
Adobe InDesign CC
MS-Windows (XP would you believe?)
