Skip to main content
Participating Frequently
November 17, 2018
Answered

Table inside text frame

  • November 17, 2018
  • 2 replies
  • 1290 views

Hello, I would like to extract table by table and place it within a text frame and then adjust the frame to the content and paste it back in its original place to finally apply an object style to it.

    app.selection.length > 0
   app.cut() 
   app.paste()  
   app.selection[0].parentTextFrames[0].select();
   app.selection[0].fit (FitOptions.FRAME_TO_CONTENT);
   app.cut() 

finally I would have to paste it in its place of origin

Can anyone please help me here?  I'm trying to learn scripting but some of these things still confuse me.  Thanks.

This topic has been closed for replies.
Correct answer Manan Joshi

https://drive.google.com/file/d/1CLkroEK_0z5Oq4hJtyXe-E61FAhitrOZ/view

Hi Manan, this is an example, in the second table the script works fine but in the first one it shows me an error because when executing the script after the paste of the table it shows me the overflowed text frame because the table is bigger than the text frame.

Apparently on line 7

          app.selection [0] .parentTextFrames [0] .select ();

does not allow you to select overflowed text frames.

In the script it ignores the object style.


Hi Franz,

Try the following line in place of the one with error

app.selection[0].parentStory.insertionPoints[0].parentTextFrames[0].select();

-Manan

2 replies

Participating Frequently
November 18, 2018

thank you for your help friend I solved the problem

Community Expert
November 17, 2018

Hi Franz,

Something like the following should work

var origTable = app.selection[0]
if(origTable.constructor.name == "Table")
{
     var origIp = origTable.storyOffset
     app.cut() 
     app.paste()  
     app.selection[0].parentTextFrames[0].select();
     app.selection[0].fit (FitOptions.FRAME_TO_CONTENT);
     app.selection[0].applyObjectStyle(app.activeDocument.objectStyles.itemByName("OS1")) //Change OS1 to name of your Object Style
     app.cut()
     app.select(origIp)
     app.paste()
}

This code will work when the selection is a table.

-Manan

-Manan
Participating Frequently
November 17, 2018

Hi Manan Joshi thanks for your help,the script is great but when the table exceeds the text frame (text frame overflowed) I get this error

Community Expert
November 17, 2018

You mean to say the original textframe within which the table existed has an overset before the code executes? Can you give me a sample document where you get this error, i am not able to reproduce the issue

-Manan

-Manan