Skip navigation
Currently Being Moderated

Automating flow tag changes

Jan 21, 2013 9:36 AM

Tags: #flows #automate_actions

(FM10 on Win7x64.)

 

I am converting content files from one template to another, from NonStandard to Standard. About twenty are chapter/container files and generated files. The rest, approximately 125, are insets.

 

The good news is that Silicon Prairie's tool sets automate much of the conversion.

 

The bad news is that body text frames in NonStandard are tagged A while those frames in Standard are tagged BodyText. When I import Page Layouts  from a Standard to NonStandard file, the NonStandard file now has two body text frames per page, one A and one BodyText. (File > Import > Formats > Page Layouts).

 

In the NonStandard files, if I can rename all A frames to BodyText frames, I can then cleanly import the Page Layouts from Standard. I then have a single set of BodyText frames to manage. Nice. 

 

I can change the flow tag of all A frames to BodyText on the master pages in each NonStandard file. But I have a lot of files.

 

How can I automate that changing of flow tags?

 

I don't see a Flow item in Find/Change.

 

Best regards,

 
Replies
  • Currently Being Moderated
    Jan 21, 2013 1:54 PM   in reply to max_drawdown

    The fastest way would be to script this using Extendscript. The core script for this could be as simple as:

     

    #target framemaker

     

    var doc = app.ActiveDoc;

    var docName = doc.Name;

    var flow = doc.FirstFlowInDoc;

     

    // set the name of the flow tag that you want to rename to

    var newName = "BodyText";

     

    // loop through all flows in a doc and rename any "A" flows to newName

     

    while (flow.ObjectValid()) {

        if (flow.Name == "A") {

            flow.Name = newName;

            }

        flow = flow.NextFlowInDoc;

    }

     

    // save the updated document

    doc.SimpleSave(docName, false);

     

    This changes all "A" flows in a document to "BodyText" and then saves the document. 

     

    You could automate this further to loop through all files/documents in a book (if you create a temporary book to hold all of the files that you want to modify ) as follows:

     

    #target framemaker


    var book = app.ActiveBook

    // get first doc in book

    var doc = book.FirstComponentInBook;

    // get first flow in the first doc

    var flow = doc.FirstFlowInDoc;


    while(doc.ObjectValid() ){

     

    // get name of current doc

         var docName = doc.Name;

     

    // loop through all flows in the current doc

         while (flow.ObjectValid()) {

             if (flow.Name == "A") {

                 flow.Name = newName;

                 }

             flow = flow.NextFlowInDoc;

         }

     

    // save the updated document using the original name

         doc.SimpleSave(docName, false);

     

    // get next doc in book

        doc =  doc.NextComponentInBook;

    }

     

     

    Please note that this a quick & dirty with minimal checks. Make backups of your originals and do all of this a temp folder with copies of the files. It's really easy to mess up a lot of files without due caution...

     

    The alternative approach could involve more manual steps. First save the files as MIF, then using a text editor (or grep command line tool) change all of these statements:

     

    <TFTag `A'>

     

    to

     

    <TFTag `BodyText'>

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 2:49 PM   in reply to max_drawdown

     

    I have the book open and selected in the tree, with no document open. To identify that script, I use File > Script > Run.

     

     

    This was a quick&dirty to show you the basics. Just iterating from the book requires you to also open each document (& close it after saving too). If all the files are open in advance, then it should work.

     

    With the possibility of nested books, groups & folders, this (iterating over all files in a book) isn't a trivial operation (anymore). If you look at any of the Adobe Extendscript of the week blogs (for example, see: http://blogs.adobe.com/techcomm/2011/11/extendscript-of-the-week-close -all-files-in-a-book-without-saving.html ) and examine the BookIterator.jsx routine in the downloadable script package, you'll see the complexity of checking for all conditions cleanly when opening book components.

     

    In the Book file, a Shift+File > Open All Files in Book  should get all of the components opened for you. Then run the script.

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 22, 2013 10:07 PM   in reply to max_drawdown

    Here's a revised script that will open, change the flow name, save and close all of the book component files. (I've tested this to be sure it works.)

     

    #target framemaker

     

    var book = app.ActiveBook;

    // get first doc in book

    var comp = book.FirstComponentInBook;

    // set flow tag names

    var newName = "BodyText";

    var oldName = "A";

     

    // loop through all docs in book

    while (comp.ObjectValid()) {

      // get name of current doc

         var docName = comp.Name;

    // open document

        var doc = SimpleOpen (docName, false);

    // get first flow in the first doc

        var flow = doc.FirstFlowInDoc;

     

      // loop through all flows in the current doc

         while (flow.ObjectValid() ) {

             if (flow.Name === oldName) {

                 flow.Name = newName;

                 }

             flow = flow.NextFlowInDoc;

         }

     

    // save the updated document using the original name

       doc.SimpleSave(docName, false);

    // close the document

       doc.Close (Constants.FF_CLOSE_MODIFIED);

     

    // get next doc in book

        comp =  comp.NextComponentInBook;

    }

     

     

    Again, this doesn't do any extensive checking, so if the files open cleanly from a book, this should be ok.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points