• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

table position

Community Beginner ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

I want to create 5 small tables in a textframe side by side. So I create them this way:

for(var i = 0; i < 5; i++) {

    var table = textFrame.insertionPoints[-1].tables.add();

    table.bodyRowCount = 2;

    table.columnCount = 1;

    table.width = 16;

    }

However, this code positions the tables one below the other and not side by side.

I haven't found out so far how I can achieve this. Help very appreciated.

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 03, 2016 Nov 03, 2016

Hi together,

yes—using anchored frames is possible.

Here some code:

// Text frame selected:

var textFrame = app.selection[0];

// Let's build a text frame with a table somewhere on the spread:

var frameWithTable = app.documents[0].layoutWindows[0].activeSpread.textFrames.add

(

    {

        geometricBounds : [0,0,100,16],

        strokeWidth : 0,

        strokeColor : "None",

        fillColor : "None"

    }

);

// Adding a table:

frameWithTable.insertionPoints[0].tables.add

(

    {

        bodyRowCount : 2,

       

...

Votes

Translate

Translate
Mentor ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Hi,

Are you able to do it manually (in GUI)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

No! 🙂

I have tried to pack the tables into textframes but that didn't work well.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

I've done it into auto-resized text frames! Interesting way! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Hi together,

yes—using anchored frames is possible.

Here some code:

// Text frame selected:

var textFrame = app.selection[0];

// Let's build a text frame with a table somewhere on the spread:

var frameWithTable = app.documents[0].layoutWindows[0].activeSpread.textFrames.add

(

    {

        geometricBounds : [0,0,100,16],

        strokeWidth : 0,

        strokeColor : "None",

        fillColor : "None"

    }

);

// Adding a table:

frameWithTable.insertionPoints[0].tables.add

(

    {

        bodyRowCount : 2,

        columnCount : 1,

        width : 16,

        contents : ["Cell 1", "Cell 2"]

    }

);

// Let's fit the frame to the table:

frameWithTable.fit(FitOptions.FRAME_TO_CONTENT);

// Duplicate and anchor the duplicates to the selected text frame:

for(var n=0;n<5;n++)

{

    var dup = frameWithTable.duplicate();

    dup.anchoredObjectSettings.insertAnchoredObject

    (

        textFrame.parentStory.insertionPoints[-1] ,

        AnchorPosition.INLINE_POSITION

    );

  

    // Maybe we need a separator character between the frames?

    textFrame.parentStory.insertionPoints[-1].contents = " ";

}

// Remove the frame we built on the spread:

frameWithTable.remove();

Have fun!

Cheers,

Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Uwe or Jarek,

A simple question: How can I find tables that follow and catch them (as an array to be exploited later)?

Only interested by tables groups (2, 3, 4, … tables), not isolated (1) table.

Thanks in advance! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Hi,

An Array of Tables from anchored textFrames could be called like:

thisTextFrame.textFrames.everyItem().tables

However Uwe's code give us a simple monostructured ones (no isolated...:)

Jarek

PS. Are you detecting Chrome getting frozen while this forum's post editor is fired, guys?

FireFox doing well on my side (Win 10, PC)...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Thanks Jarek! 

It's the first way for me. I'm working on Uwe's approach.

My 2nd way is to insert tables that follow (as usual in current text) in a new table.

So, I've the same question:  How can I find and catch them?

Thanks in advance!

(^/)

I don't use Chrome!  😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Hi Obi-wan,
I'm not sure what you are asking here.

Do you want to track tables that are inserted with inline anchored text frames?

Example
Find all nested tables in the selected text frame.
Where the depth of nesting is 1 . That means find a table that sits inside an anchored text frame.

The first table in the text frame should not count. It is not nested.

FindNestedTables-in-SelectedTextFrame.png

We could do:

app.selection[0].textFrames.everyItem().tables.everyItem().getElements();

That would result in an array of 10 tables.

You could add all "regular" tables in the text frame as well:

var tablesArray = app.selection[0].tables.everyItem().getElements();

var nestedTablesArray = app.selection[0].textFrames.everyItem().tables.everyItem().getElements();

nestedTablesArray.concat(tablesArray);

That array would contain 11 tables.

How deep do you want to nest your tables?

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Hi Uwe,

I would like to have an answer to this old topic:

Select several tables …

I mean: in this topic, I wanted to select the 3 tables that follow in a current text frame so that I can place them, one table per cell, in a new table.

The deal is to "horizontally" place following tables, eventually "marked" with a condition or a specific para style.

The way you propose with "inline" text frames is an excellent other way I take too.

I would like to have the 2 layout options depending on the layout context.

(^/) 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Hi Obi-wan,

hm yes, that would work either way. Just single out the text with the three tables and work with the special characters that hold the tables. Would you want to get the tables from that text by text.tables.everyItem().getElements() and loop through the array to get the character that you'd like to move? Or would you like to do a Text Search with special character <0016> on the text?

But: Since your case is more special than the OP's one, I suggest we maybe should continue to discuss your problems in a different thread. Let's have the original poster—martine55225436—the say on that.

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Uwe,

I answer you and then we could go on on my old topic! 

In a layout, I could need to horizontally place following tables but not systematically (for different reasons).

So, my idea is to manually apply a condition to the "table support" para and so "mark the tables to be treated.

When done, I launch the script that loops through the doc to find these "conditional" paras containing each a table!

At this step, 2 options: yours or mine!

Imho, yours could be lighter and more interesting, but it depends on the context! 

Maybe, 2 conditions to manage the 2 ways! Of course, in the same script!

I don't want you to write the script. However, your help could be great (Jarek and Kai too!) to validate my code writing!! 

Last comment on this point here! Next at:  Select several tables …

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 03, 2016 Nov 03, 2016

Copy link to clipboard

Copied

Jarek,

I would be very interested by a way to do it!

I thought about 2 ways: insert them into another table or place them into anchored inline text frames!

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Sadly it would be possible for 4, not 5 tables, with the spaning columns feature: Split 4

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Hi Kai,

The problem with Uwe's way (anchored inline text frames) and yours (span feature) is that we can't correctly control the horizontal space between the tables. It's a reason for me to have the other option!

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

Oh we can control the positions.
By using tabulators perhaps.

HorizontalPositioning-InlineTextFrames-WithTables.png

Regards,
Uwe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2016 Nov 04, 2016

Copy link to clipboard

Copied

LATEST

Yeap! I think too but not really easy! use insets management in the "layout table" could be cooler! 

(^/)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines