Skip to main content
sam95317750
Known Participant
June 26, 2019
Question

How can I split a .fm document based on the h1/h2 headings using extended script?

  • June 26, 2019
  • 1 reply
  • 1071 views

I have a .fm document that I need to split into multiple files based on h1 or h2 paragraph tags. The headings and its content should be copied or saved/split into separate files.

This topic has been closed for replies.

1 reply

Legend
June 26, 2019

Hi, your question is broad. I know how I would do it and I think several others would too, but no one is likely to write a script for you. I would do something like:

1) Set up a template to receive the h1/h2 sections, that I will paste in the content and Save As to the separate files.

2) Starting with the first paragraph in the flow (probably something like doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf), iterate through all paragraphs (pgf.NextPgfInFlow).

3) At each h1 or h2 paragraph (pgf.name=="h1" etc.) remember the paragraph object. Then go to the next h1/h2 pgf and remember the previous paragraph.

4) Create a text range between the two paragraphs, select the text, and copy the text to the clipboard. You could also cut.

5) Paste it over the contents of the template and do a save as

6) Keep iterating.

All of these steps require substantial expertise. I don't know what your current skill level is. Likely, you won't get too much more help unless you come here with more specific questions.

Russ

Inspiring
June 26, 2019

my approach to solve such problems is a Little unconventionial, but it worked well in several Scenarios my projects

1. Create a EDD with a flat structure (only p, tables and some Special object like graphics, xrefs) and assign Paragraph styles by attributes

2. Import this EDD in your template (nothings changes)

3. create a simple Conversion table which generates that flat structure (Standard Generation gives a good starting Point)

4. convert document to a structured one via conversion table

5. Setup a simple XML application

6. Add an XSLT as postprocess which splits documents, when document is saved to XML

7. Select "File Save As XML"

8. open splitted XML files angain and save it as FM binaries. Remove structure

9. create a simple scripts which automates save and open actions

All is done with FM board functionality with only a Little bit scripting

Hope this helps

Markus