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

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

Community Beginner ,
Mar 13, 2014 Mar 13, 2014

Copy link to clipboard

Copied

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?
TOPICS
Scripting

Views

1.0K

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 ,
Mar 13, 2014 Mar 13, 2014

Copy link to clipboard

Copied

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.

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 ,
Mar 20, 2014 Mar 20, 2014

Copy link to clipboard

Copied

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.

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 ,
Mar 21, 2014 Mar 21, 2014

Copy link to clipboard

Copied

Sorry, I did not understand the target here …

Please provide a idml-file with the start-state and your final-state. I must have a look at your table style and did not understand why you want to create a new textframe.

btw: You get two texttframes, because you create two with "add".

var curDoc = app.activeDocument;

var curFrame = curDoc.textFrames.add( {geometricBounds: ["30pt", "30pt", "300pt", "200pt"]} );

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 ,
Mar 24, 2014 Mar 24, 2014

Copy link to clipboard

Copied

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.

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 ,
Mar 24, 2014 Mar 24, 2014

Copy link to clipboard

Copied

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?

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 ,
Mar 24, 2014 Mar 24, 2014

Copy link to clipboard

Copied

I haven’t the time, to investigate here further, sorry. As a script beginner, it needs much more time for me, than a pro would need for that. So maybe others could dive in here or you must investigate in a paid-script.

What I have so far:

1. To get the position of the frames, I would anchor them at the first position of the current found (and maybe release them later)

2. To have more control of the position, the next version of the script assumes a objectStyle "Marginalien" with custom anchored settings

3. There a two ways to bring your table in the anchored frame:

a) Create your table first and move the table to the new textFrame >> Did not know how to do that, since I had serveral problems with the index

b) Create the textframe first, move the found to the new frame and convert then to table >> In this case I’m wondering why I get no index issues, but it worked

// das aktuelle Dokument

var curDoc = app.activeDocument;

// die aktuelle Auswahl

var curSel = app.selection[0];

// die Sucheinstellungen zurücksetzen

app.findGrepPreferences = app.changeGrepPreferences = null;

// die Sucheinstellungen setzen

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

var result = curSel.findGrep( true );

 

// eine Schleife durch die Fundstellen

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

    // die letzte Fundstelle

    var curResult = result;

    var iP = curResult.insertionPoints[0];

    var newTf = iP.textFrames.add({geometricBounds: [ 0, 0, "30mm", "80mm"]});  

    newTf.appliedObjectStyle = curDoc.objectStyles.itemByName("Marginalien"); 

    var newContent = curResult.move(LocationOptions.AFTER, newTf.insertionPoints[0]);   

    // Fundstelle in Tabelle konvertieren

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

    // Erste und letzte Spalte löschen

    curTable.columns[0].remove();

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

    // Tabelle wieder an Textrahmen anpassen

    var tFrame = curTable.parent;

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

    curTable.width = fWidth;

    // Erste Zeile in Kopfzeile wandeln

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

    // Tabellenformat zuweisen

    curTable.appliedTableStyle = "Redtable";        

    // vorsichtshalber Abweichungen vom Tabellenformat löschen    

    curTable.clearTableStyleOverrides( true );

    // den Whitespace säubern

    app.findGrepPreferences = null;

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

    app.changeGrepPreferences.changeTo = "";

    curTable.changeGrep();

}

app.findGrepPreferences = null;

For own interest:

It would be great, if someone could show me on a simple example, how I can add a frame before a given table and move the table (or the paragraph that holds the table) to that frame. At the moment I get a warning here, something like: You cannot move the content to the same position.

Thanks

kai

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 ,
Mar 24, 2014 Mar 24, 2014

Copy link to clipboard

Copied

I think I can help you with at least pointing you in a direction with that one. I have found a commandline that moves something from somewhere to somewhere else. I have very little idea of how it works, but it does as I have moved around things using that thing.

var myParagraph = myTextFrame.paragraphs.item(0);

var myDestinationTextFrame = myDestinationPage.textFrames.add(undefined, undefined, undefined, {geometricBounds:["30mm", "50mm", "200mm", "170mm"]});

myParagraph.move(LocationOptions.atBeginning, myDestinationTextFrame.parentStory);

Basically, at this point in my horribly broken and completely unusable piece of junk script, I create the table, assign the style, clear the cells and then move the created table to that textfield. Does that help at all? EDIT: Also, I read somewhere that InDesign doesn't like it when you're trying to move all text in a textframe. I haven't tried that one out yet, but I can believe it.

Also, yes, of course. I see now where I created the second text frame. I feel stupid now. As an excuse, I present this: I was too focused on the numbers.

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 ,
Mar 30, 2014 Mar 30, 2014

Copy link to clipboard

Copied

LATEST

Your lines are not really helpful!

The following code should solve your problem verry close to your example. At the moment the table will be anchored in the paragraph with content before. The position of the table-frame is controlled by the object style "Marginalien".

// das aktuelle Dokument

var curDoc = app.activeDocument;

// die aktuelle Auswahl

var curSel = app.selection[0];

// die Sucheinstellungen zurücksetzen

app.findGrepPreferences = app.changeGrepPreferences = null;

// die Sucheinstellungen setzen

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

var result = curSel.findGrep( true );

// eine Schleife durch die Fundstellen

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

    // die letzte Fundstelle

    var curResult = result;

    var curIP = curResult.insertionPoints[0].index;

    var curStory = curResult.parentStory;

    var IPs = curStory.insertionPoints.itemByRange(0 , curIP);

    var nParas = IPs.paragraphs.length-1;

    if ( curStory.paragraphs[nParas].contents == "\r" ) {

        curStory.paragraphs[nParas].remove();

        var a = curStory.paragraphs[nParas-1].insertionPoints[0];

    }

    else {

    var a = curStory.paragraphs[nParas].insertionPoints[0];

    }

    var newTf = a.textFrames.add({geometricBounds: [ 0, 0, "30mm", "80mm"]});  

    newTf.appliedObjectStyle = curDoc.objectStyles.itemByName("Marginalien"); 

    var newContent = curResult.move(LocationOptions.AFTER, newTf.insertionPoints[0]);   

    // Fundstelle in Tabelle konvertieren

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

    // Erste und letzte Spalte löschen

    curTable.columns[0].remove();

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

    // Tabelle wieder an Textrahmen anpassen

    var tFrame = curTable.parent;

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

    curTable.width = fWidth;

    // Erste Zeile in Kopfzeile wandeln

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

    // Tabellenformat zuweisen

    curTable.appliedTableStyle = "Redtable";        

    // vorsichtshalber Abweichungen vom Tabellenformat löschen    

    curTable.clearTableStyleOverrides( true );

    // den Whitespace säubern

    app.findGrepPreferences = null;

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

    app.changeGrepPreferences.changeTo = "";

    curTable.changeGrep();

}

app.findGrepPreferences = null;

// die überflüssigen Returns löschen  

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

app.changeGrepPreferences.changeTo = "\\r";

curDoc.changeGrep();

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