ExtendScript: Reading vs. writing InDesign references
Hi all-
Not hugely versed in Javascript as well as InDesign, so perhaps this is a language rather than application question. I have some code that looks like this:
var theSelection = app.documents.firstItem().selection;
var theTextFrames = theSelection[0].parentStory.texts;
var numTextFramesSelected = theSelection.length;
var documentFilePath = app.activeDocument.filePath;
function ROW(i){
return theTextFrames.item(0).associatedXMLElements;
}
function DATA(i, COL){
return ROW(i)[COL].xmlElements.item(0).contents;
}
function setDATA(i, COL, boxContents){
ROW(i).item(COL).xmlElements.item(0).contents = boxContents;
}
So, the notion is that the element references that are used in the functions are built from variables that contain portions of the element reference. The portions of the code that READ the elements seems to work OK, but the portions that WRITE to the elements inevitably fail. Any thoughts on what I'm doing wrong here?
A further question: I know I can refer to my InDesign elements like so:
app.documents.firstItem().selection[0].parentStory.texts[0].associatedXMLElements
but my past association with Applescript always encouraged me to get my references as few times as possible, I guess because of the cost of inter-application communication in Applescript's case.
But with ExtendScript, is there a performance penalty in getting these references each time you run through a loop?
Thanks, Charles