-
1. Re: Automating flow tag changes
Arnis Gubins Jan 21, 2013 1:54 PM (in response 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'>
-
2. Re: Automating flow tag changes
max_drawdown Jan 22, 2013 8:46 AM (in response to Arnis Gubins)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;
}
-
3. Re: Automating flow tag changes
max_drawdown Jan 22, 2013 9:50 AM (in response to max_drawdown)@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,
-
4. Re: Automating flow tag changes
Arnis Gubins Jan 22, 2013 2:49 PM (in response 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.
-
5. Re: Automating flow tag changes
Arnis Gubins Jan 22, 2013 10:07 PM (in response 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.
-
6. Re: Automating flow tag changes
max_drawdown Jan 24, 2013 7:32 AM (in response to Arnis Gubins)@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,


