Answered
Clipping a table in a textframe with pasteInto
Hi,
My use case is to be able to take a table which is inside a text frame and "pasteInto" the same text frame, so that the table clipped to the text frame dimensions.
Here's the code snippets I have got so far:
// Create the table
var myTable = textFrame.insertionPoints[-1].tables.add(...)
// Generic code to check the text frame in which the table is located
var topTextFrame = undefined
for (var i = 0; i < g.doc.textFrames.length; i++) {
var thisTextFrame = g.doc.textFrames[i];
// Check if the text frame's story contains the nestedTextFrame as an anchored object
if (thisTextFrame.textFrames.itemByID(textFrame.id).isValid) {
topTextFrame = thisTextFrame;
break;
}
}
for (var i = 0; i < g.doc.textFrames.length; i++) {
var thisTextFrame = g.doc.textFrames[i];
// Check if the text frame's story contains the nestedTextFrame as an anchored object
if (thisTextFrame.textFrames.itemByID(textFrame.id).isValid) {
topTextFrame = thisTextFrame;
break;
}
}
// If we located the topTextFrame, "paste Into" the table back into the same topTextFrame
if (topTextFrame) {
$.writeln("Top text frame found.");
app.select(textFrame);
app.copy();
app.select(NothingEnum.NOTHING);
app.select(topTextFrame);
app.pasteInto(); // At this point, the top level text frame is getting convered to a graphic frame
}
Q1. Is this the right way to do pasteInto for my use case?
Q2. I observe on line app.pasteInto that the text frame is getting converted to a graphics frame. Is this expected and can we have a custom behavior to retain the topTextFrame as a text frame?
Q3. What would be a generic code to identify the graphic frame id and the new table id (since the original myTable is already removed as part of pasteInto)
Thanks,
