[Extendscript] Trying to insert text, how do I find the Doc that a particular object is in?
I have a cell object and I would like to add text to it. I'm trying to call `doc.AddText(textLoc, 'cell text');`, but I don't have the `doc` object, I only have the `cell` object.
function setCellText(cell, text) {
// Create a text location at the beginning of the cell
var textLoc = new TextLoc();
textLoc.obj = cell;
textLoc.offset = 0;
// Delete all the paragraphs after the first (new) paragraph
while (cell.FirstPgf.id != cell.LastPgf.id) {
cell.LastPgf.Delete();
}
cell.LastPgf.Delete();
// Write the specified cell value to the text location
doc.AddText(textLoc, text); // <== !! How do I get the doc for the current cell?
}
Rather than adding a `doc` parameter to every function in the call statck, I'd like to be able to determine the `doc` from the cell itself. I have some code that will look up the page an object is on, but I couldn't figure out how to get to the parent doc anywhere along the way.
At a higher level, is there an alternate/better way to add text to a cell than `doc.AddText`? I suspect not, but just in case.
For reference, here is the function to get the Page:
fucntion getDoc(obj) {
// ???
}
function getPage(obj) {
if (obj.PageFramePage != undefined && obj.PageFramePage.ObjectValid())
return obj.PageFramePage;
if (obj.FrameParent != undefined && obj.FrameParent.ObjectValid())
return obj.FrameParent.getPage();
if (obj.InTextFrame != undefined && obj.InTextFrame.ObjectValid())
return obj.InTextFrame.getPage();
if (obj.TextLoc != undefined && obj.TextLoc != null)
return obj.TextLoc.obj.getPage();
return null;
}
Cross posted on SO: https://stackoverflow.com/q/68230503/892536
