Skip to main content
gisteppen
Known Participant
February 11, 2014
Question

Best way to copy range of paragraphs

  • February 11, 2014
  • 1 reply
  • 1009 views

I'm getting all the changebars in the files of a book, and copying them out into a separate, single change document. Once I find the Pgf with the changebar, what would be the best way to copy the info out to the change doc? I want to copy the entire section that contains the changebar.

I figured I would move backwards and find the most recent section heading and set the beginning of a TextRange there at the beginning of that Pgf. Then I move forward and find the following heading pagagraph, and move back one pgf from that and set that as the end of the range.

At that point should I use copy and paste into the new document?

Thanks, Mark

This topic has been closed for replies.

1 reply

4everJang
Legend
February 11, 2014

Hi Mark,

Your thinking is right, but a couple of details are important:

1. Setting the TextRange

Create two TextLoc objects, one pointing at your first Pgf with offset 0, the second one pointing at the lasst Pgf in your section, with offset Constants.FV_OBJ_END_OFFSET. Then create the TextRange object, using the start and finish TextLoc objects.

2. Copying the TextRange

Set the TextSelection property of the Document to the TextRange you created. Then use the Copy method on the Document. The Copy method does not take arguments, it always takes the current TextSelection.

3. Pasting the materials

In the target document, set the text cursor by creating a TextRange with the same beg and end TextLoc objects (pointing at the point where you want to insert the text. Then set the TextSelection of the target Document to the new TextRange. Use the Paste method with the right flags you need (see page 482-483 of the FrameMaker 10 Scripting Guide.

Another method would be to make all text without change bars hidden, but that would take a little more time and effort to explain.

I hope this helps.

Jang

gisteppen
gisteppenAuthor
Known Participant
February 11, 2014

Thanks Jang for giving me which pieces to use in which combinations. I'm trying this out now.

As I loop back to get the previous heading, am I going to have trouble getting Pgfs in document order? I was planning on using Pgf.PrevPgfInFlow, NextPgfInFlow to do this.

Thanks, Mark

gisteppen
gisteppenAuthor
Known Participant
February 11, 2014

Here's my first rudimentary working code that selects the changebar Pgf (just one at this point), copies it, and pastes it into a second changes document. Thanks for your help Jang.

// findChangebar() returns Pgf object that has a changebar.

changePgf = findChangebar(doc);

if (changePgf) {

    var tBegin = new TextLoc();

    var tEnd = new TextLoc();

    var chgRange = new TextRange();

    tBegin.obj = changePgf;

    tBegin.offset = 0;

    tEnd.obj = changePgf;

    // This constant gets you the end of the paragraph.

    tEnd.offset = Constants.FV_OBJ_END_OFFSET;

    chgRange.beg = tBegin;

    chgRange.end = tEnd;

    doc.TextSelection = chgRange;

    doc.Copy();

    // Text selection now held in clipboard, available to other docs.

     // changesDoc is already open.

    var firstChgPgf = changesDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

    var changesTbeg = new TextLoc();

    var changesTend = new TextLoc;

    var chgRange = new TextRange();

    changesTbeg.obj = firstChgPgf;

    changesTbeg.offset = 0;

    changesTend.obj = firstChgPgf;

     // I found it was not necessary to select to the end of the paragraph, so offset 0.

    changesTend.offset = 0;

    chgRange.beg = changesTbeg;

    chgRange.end = changesTend;

    changesDoc.TextSelection = chgRange;

    changesDoc.Paste();

}