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

Automating flow tag changes

Participant ,
Jan 21, 2013 Jan 21, 2013

Copy link to clipboard

Copied

(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,

Views

1.4K

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
LEGEND ,
Jan 21, 2013 Jan 21, 2013

Copy link to clipboard

Copied

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'>

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
Participant ,
Jan 21, 2013 Jan 21, 2013

Copy link to clipboard

Copied

Wow!  Thanks for such a complete suggestion.

I'll test this when I get back to my desk and will report back here.

____________

Thanks again. First tests complete.

The single-document version works perfectly. The book version does not appear to run at all.

I took the liberty of editing the single-document version, which is a pretty big step considering I don't know Javascript or ExtendScript.

Here's the working single-document version:

#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";

var oldName = "A"; // added this

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

while (flow.ObjectValid()) {

    if (flow.Name ==oldName) {     // changed this

        flow.Name = newName;

        }

    flow = flow.NextFlowInDoc;

}

// save the updated document

doc.SimpleSave(docName, false);

And here's the book version. Apparently it doesn't start (book is open and selected in the tree):

#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;

// set flow tag names

var newName = "BodyText";

var oldName = "A";

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 == oldName) {

             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;

}

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
Participant ,
Jan 22, 2013 Jan 22, 2013

Copy link to clipboard

Copied

@Arnis,

At a glance, I don't know why the book traversal is not working. The code seems consistent with other examples that I have found.

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

Best,

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
LEGEND ,
Jan 22, 2013 Jan 22, 2013

Copy link to clipboard

Copied

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-s... ) 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.

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
LEGEND ,
Jan 22, 2013 Jan 22, 2013

Copy link to clipboard

Copied

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.

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
Participant ,
Jan 24, 2013 Jan 24, 2013

Copy link to clipboard

Copied

LATEST

@arnis,

Thanks! Still away from my desk. Will get back to this as soon as a I can.

You're not kidding about the complexity to handle all scenarios.  Not a trival thing.


Best,

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