Skip to main content
Known Participant
November 11, 2024
Answered

Clipping a table in a textframe with pasteInto

  • November 11, 2024
  • 1 reply
  • 1721 views
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;
    }
}
 
// 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,
 
 
This topic has been closed for replies.
Correct answer Robert at ID-Tasker

@asaxena

 

You mean red frame is a graphic frame?

 

If you've a TextFrame - you can only Anchor / InLine other objects - as characters. 

 


@asaxena

 

In order to achieve what I think you want to achieve - you would've to pasteinto your table into a Rectangle then Anchor / InLine your Rectangle into another TextFrame.

 

1 reply

Peter Kahrel
Community Expert
Community Expert
November 11, 2024

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.

 

This isn't very clear. Please explain in more detail, with a screenshot of the before and after situations of what you want to achieve.

 

As to pasteInto, in scripting you'd use duplicate() or move(), thay're more reliable, and you can maintain references. Much more robust than copying and pasting.

asaxenaAuthor
Known Participant
November 11, 2024

Sure. My situation is like so:

I have a blue swatch table which is inside a red swatch text frame:

The Layers show up like so:

 

 

What I am after, is to start from the above layout, and then clip the table to the bounds of the text frame like so while retaining the blue as the table Text Frame and the Red as the Text Frame.

Unfortunately the Layer window reports that the blue frame is now "graphics frame" instead of the Text Frame

 

Thanks

Peter Kahrel
Community Expert
Community Expert
November 11, 2024

You can't clip a table like that. The only way to achieve that is what InDesign already does for you: convert the frame with the table to a graphic.

 

You could cover the extending part of the table with a text frame and give it the Paper fill and group the whole thing, that's the closest you'll get I think.