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

Text to table?

New Here ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Hi all

Is it possible to produce a script that creates a table from the currently selected text?

I can find plenty of discussion about going the other way (ie converting a table to text) but none about converting a text selection to a table. I've looked everywhere I can think of, including the Adobe FM Scripting Guide, but no joy, so I'm beginning to doubt it's even possible.

Apologies if the scarcity of info is because it's so laughably simple that everyone else has worked it out -- I'm still at the stage where I'm quite surprised to be able to create a table at all (using NewTable), never mind anything more sophisticated!

Any clues will be extremely gratefully received.

Many thanks

TOPICS
Scripting

Views

493

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 ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Yes, this is definitely possible. There is no built-in function that you can call, so you would have to write your own. Of course, FrameMaker already has a Text to Table command that you can use, so what would be your reason to use a script? Would you want to process a lot of different sections of text at once? Please outline your overall objective and we can probably at least get you started. -Rick

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
New Here ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Thanks Rick -- at least I now know I haven't overlooked an existing function.

I'm trying to automate as much of the formatting as possible on a large document that is to include several thousand tables (it's currently largely unformatted). Hence my desire to minimize the amount of manual formatting involved!

What I'm trying to achieve is this:

1. Find every occurrence in the current document of the word 'Syntax', whose paragraph format is 'Heading 5'.

2. Select the whole of the next paragraph.

3. Convert this paragraph to a particular table format (FormatA, for the sake of argument).

If I can't directly convert the para, do I have to select it, cut it, create the table and then move the text into the table? (I was hoping there was a neater solution, but I'm not really bothered as long as it works!)

Thanks again

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 ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Hi Elaine, OK so if it is just the next paragraph after the Heading 5, I am assuming a single-row table. How many columns will the table have? Does the content of the paragraph just go in one cell, or is it delimited and go into multiple cells?

Here is a basic outline of what I would do with the script.

1) Find the paragraph following the appropriate Heading 5. It is not necessary to actually select this paragraph.

2) Insert a new paragraph following this one. I would tag it with some kind of small, anchor paragraph format.

3) Insert my FormatA table into this new paragraph.

4) Grab the text from the paragraph and place it into the table cell(s).

5) Delete the paragraph.

Each of these steps can be done with some code. Once you have each step coded, you can put it together in a complete script. Please let me know which individual pieces you need help with.

Also, I have some discretionary time this morning if you want to have a short web meeting to discuss it (no charge of course). If you are interested, please contact me at rick at frameexpert dot com and I will send you a meeting link. Thanks. -Rick

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
New Here ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Hi Rick

Yes, that's exactly right -- it's a single row, single column table (I've got some more complicated tables later, but I'm hoping that once I understand how to do this with the easy ones, I'll be able to figure them out).

Thanks for the clarification of the steps I need to take - now that you've outlined them for me, I should be able to make some progress. I'll be sure to take up some more of your time if I get completely stuck!

(Thanks also for the extremely kind offer of a web meeting -- unfortunately, I'm getting hauled off into a meeting here shortly and I'm not sure when it'll finish, so I'll have to postpone my efforts on this until later.)

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 ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Some code for Step 2:

#target framemaker

var doc = app.ActiveDoc;

// Paragraph containing the insertion point.

// This will be the paragraph that you want to convert to a table.

var pgf = doc.TextSelection.beg.obj;

// Add a new paragraph after the current paragraph.

var newPgf = doc.NewSeriesPgf (pgf);

// Apply an anchor paragraph format to it.

applyPgfFmt (newPgf, "anchor", doc);

function applyPgfFmt (pgf, name, doc) {

   

    // Applies a paragraph format to text.

   

    var pgfFmt = 0;

   

    pgfFmt = doc.GetNamedPgfFmt(name);

    if (pgfFmt.ObjectValid()) {

        var props = pgfFmt.GetProps();

        pgf.SetProps(props);

    }

    else {

        pgf.Name = name;

     }

}

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 ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

One question about Step 4: Does the text that you are moving from the paragraph to the table have any character styling applied to it? The answer will determine the best method to use. Thanks.

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
New Here ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

LATEST

Hi Rick

Thanks very much for the help with Steps 2 and 3 -- it is much appreciated!

In answer to your query about Step 4, no character styling is applied and when I tested the steps manually, the moved text (correctly) takes on the paragraph tag that is defined in the table style. I hope that means that it slightly simplifies things...

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 ,
Feb 19, 2015 Feb 19, 2015

Copy link to clipboard

Copied

Here is basic code for Step 3:

#target framemaker

var doc = app.ActiveDoc;

// Paragraph containing the insertion point.

// This will be the paragraph where you will insert the table.

var pgf = doc.TextSelection.beg.obj;

// Create a text location to hold the table.

var textLoc = new TextLoc (pgf, 0);

// Insert the table.

var tbl = doc.NewTable ("Format A", 1, 1, 0, 0, textLoc);

A couple of things to note here: 1) You will have to make sure the specified table format exists, or you will get an error. 2) You will probably want to resize the table, but right now I want to keep things simple.

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