Skip to main content
The Gothamite
Known Participant
March 13, 2014
Question

Textile-Conversion: Can create Table with Style applied, but need to have it in separate Textfield

  • March 13, 2014
  • 1 reply
  • 1255 views

Aloha everyone

I'm in need of a bit of help. So I'm working on a Textile-conversion script and I'm almost done (with a lot of thanks to you guys), That last bit concerns tables. And all I need to do is basically take it out of the main text field and make a separate one.

So this is a table with one header row as seen in Textile.

|_. name |_. age |_. sex |

| joan | 24 | f |

| archie | 29 | m |

| bella | 45 | f |

And from this, I produce a table with the style "RedTable2" using this code.

// current selection

var curSel = app.selection[0];

// reset searchparameters

app.findGrepPreferences = app.changeGrepPreferences = null;

// set search parameters

app.findGrepPreferences.findWhat = "(\\|.+\\r)+\\|.+";

var result = curSel.findGrep( true );

app.findGrepPreferences = null;

 

// loop through findings

for ( var f = 0; f < result.length; f++ ) {

          // last finding

          var curRes = result;

          // convert to table

          var curTable = curRes.convertToTable("|");

          // delete first and last row

          curTable.columns[0].remove();

          curTable.columns[-1].remove();

          // fit table to frame (doesn't always quite work)

          var tFrame = curTable.parent;

          var fWidth = tFrame.geometricBounds[3] - tFrame.geometricBounds[1];

          curTable.width = fWidth;

          // make first table a header row

          curTable.rows[0].rowType = RowTypes.headerRow;

          // add Style

          curTable.appliedTableStyle = "RedTable2";                    

          // delete formatting that doesn't fit RedTable2    

          curTable.clearTableStyleOverrides( true );

          // Delete Textile Header Row formatting

          app.findGrepPreferences.findWhat = "\\s+$|^\\s+";

          app.changeGrepPreferences.changeTo = "";

          curTable.changeGrep();

     app.findGrepPreferences.findWhat = "_\\. ";

          app.changeGrepPreferences.changeTo = "";

          curTable.changeGrep();

}

app.findGrepPreferences = null;

Now, that last bit I need is this.

  • The converted table should be in a new Text Field, separate from the source text I can find.
  • Can I set the text wrap of that new text field to Jump Object and add a top and bottom offset of 7mm?
This topic has been closed for replies.

1 reply

Kai Rübsamen
Participating Frequently
March 13, 2014

First of all, it is verry uncool, if you ask your questions in multiple forums. Feel free, to choose only one forum for your questions (see also your hyperlinks-thread)

It seems that you posted my code here. As I told you at hds, it is always a good idea to provide some examples, before / after. It is not clear what "should be in a new Text Field" means and why you need that.

The Gothamite
Known Participant
March 20, 2014

Hey Kai,

Nice to see you here. I am very sorry to have offended you. While it's perfectly obvious that I shouldn't crosspost code-things, it seriously didn't occur to me in the heat of the moment. I apologize. I won't do it again.

And after one of the busiest few days I've had in a long long while, I can follow this up with an example. As I don't do the content of the boxes, I work with a lot of example and Llorem ipsum. I'm just doing layouts. So you'll have to make do with silly text everywhere, I'm afraid.

Let's say I have this.

http://i.imgur.com/Ec1Y7qS.jpg

And then I run my script. The script does its thing and this should be the outcome.

http://i.imgur.com/frAImvI.jpg

The settings on that table are TableStyle = "RedTable" and the text wrap is set to "Wrap around bounding box". Basically, I would be happy if the new text frame with the table inside it would float somewhere outside the text frame it came from. Basically, in sight of where it was found or something.

I even had time to fidget around some code earlier today and I came up with this. This generates two text boxes for some reason.

    app.activeDocument.textFrames.add ();

    var myFrame = app.activeDocument.textFrames.add ();

    myFrame.geometricBounds = ["30pt", "30pt", "300pt", "200pt"];

I suspect it has to do with the two 30s in there, but if I remove those, the code goes bust. I also fail to get the content from the textframe with the main text into the newly created textframe.

Jongware
Community Expert
Community Expert
March 24, 2014

The goal of the entire exercise is this: For ease of layout, the tables need to be in separate text fields. So the script will create the tables, put them in separate text fields and move them out of the way for the time being until a human comes along and drags them into the place where they fit best.

And here's an IDML for you to experiment around with: http://www.sendspace.com/file/3jyi12

Also, I don't understand where I create the second text frame there. According to me, I create only one where I give the four reference points needed for a text frame to be created. Where exactly are the bits that make a second frame? And how do I get it to no longer create a second frame?

All in all, tables in InDesign are a neverending source of confusion for me.


A quick answer to this part:

The Gothamite wrote:

Also, I don't understand where I create the second text frame there. According to me, I create only one where I give the four reference points needed for a text frame to be created. Where exactly are the bits that make a second frame? And how do I get it to no longer create a second frame?

... where you did this:

This generates two text boxes for some reason.


    app.activeDocument.textFrames.add ();   #1

    var myFrame = app.activeDocument.textFrames.add ();   #2

Capisce?