ExtendScript of the Week: Change Styles (Paragraph / Character / Table)

This week in “ExtendScript of the Week” initiative we will showcase an ExtendScript which will Find/Change Paragraph Styles, Character Styles and Table Styles on the body page of the document. This script demonstrates one of the several workflows where ExtendScript can be used to do tasks in an intuitive and easy way. The script works on Book as well as single FrameMaker / MIF files.

Info

Please note that there is a newer version of this script with much improved functionality here.

About this Script

  • On running the script this dialog appears:

    Change Style UI

  • The dialog contains three radio buttons – namely “Para Style”, “Char Style” and “Table Style” and two buttons “Change” and “Cancel”.
  • You can choose the style type to be changed by clicking on the appropriate radio button and the FIND and CHANGE dropdowns are populated by the styles existing in the active document or if run on a book the styles are taken from the first non generated file in the book.
  • E.g., if you run the script on the attached Sample_Book.book/Doc1.fm then choose “Para Style” radio button.
  • Now choose NewParaFormat-Blue in the FIND dropdown.
  • Choose NewParaFormat-Red in the CHANGE dropdown.

    Choose Styles in UI

  • Click on Change button.
  • Now the script will iterate through all paragraphs of all components of the book and wherever the paragraph format is NewParaFormat-Blue, it is changed to NewParaFormat-Red.

    Output File

  • Similarly you can change character formats and table formats in a book or document.
  • After changing the style, an alert will appear informing the user about the number of changes that were done in the operation.

    Number of Changes

Steps to Install

  1. Download the zip file from ChangeStyles
  2. Unzip the files and copy “ChangeStyleMenu.jsx” and “ChangeStyle” folder in startup folder located at “C:\Program Files\Adobe\AdobeFrameMaker10\startup”

How to use the Script

  1. Launch FrameMaker
  2. Open a Book File or FM/MIF File
  3. Run Change Styles from “File -> Utilities -> Change Styles …
  4. This will run the script and ask you for inputs to change the style.
  5. Choose the style to be changed in ‘Find’ dropdown.
  6. Choose the style to be applied in ‘Change’ dropdown.
  7. Click on Change button.
  8. If the script is run on an open FM/MIF file the styles will be changed without saving the document.
  9. If the script is run on a Book, all the FM/MIF components which are closed are opened invisibly, the styles are changed and then the files are closed after saving.

I hope this will prove useful to many folks and you can add extra functionality as per your requirements to these scripts to make it even more powerful.

Regards,
Bharat Prakash

(Resources: ChangeStyles)

Bharat Prakash

Bharat Prakash

Bharat Prakash is the Product Solution Consultant for the Technical Communication unit at Adobe and has more than a decade’s experience in software development, testing and consulting. He has extensive experience in end-to-end deployment of features from conception to delivery with wide exposure to different SDLC models. Bharat is an expert in Structured Authoring and various industry standards like DITA and MathML.

11 thoughts on “ExtendScript of the Week: Change Styles (Paragraph / Character / Table)

  1. At this point I’ve had the opportunity to try this script in a couple of “real world” situations, and I have to say, it is very hit and miss. Something is very wrong with this script since it actually changes only a fraction of the total occurances of a paragraph tag to the new tag and ignores other occurances. I expect the problem is in how it is stepping through the paragraphs and deciding if it is a valid paragraph to change to the new format. Could the writer of the script address this complaint. I’m sure the fix would be instructive to all of us who are interested in Extendscript scripting in FrameMaker.
    Thanks.

  2. I tried this script on a document with two paragraphs called Bulleted and BulletedOutdent. At first the script only changed some of the instances (ignoring others). Finally, it saw none of the Bulleted paragraphs and changed none of them. Bug?

    Also, it would be nice if the menu of paragraph formats were sorted into alphabetical order rather than appearing in some random order.

    I’d be happy to send you the file if you want to look at these problems.

    Thanks you.

    Craig Ede

  3. WOW!

    I have multiple documents which need to have character style changes. This saved me hours, and hours, and hours.

    Thank you very much!

  4. Hi Anh,

    I have fixed the issue and mailed you the updated scripts. Kindly let me know if there are any more issues.

    Thanks,
    Bharat Prakash(bharatp@adobe.com)
    FrameMaker Engineering

  5. I’m having trouble changing paragraph tags. It works in the sample fine. But when I use it on my files, it reports that 0 changes have been made when I select valid parameters. Also, in one instance where it does work, it only changes one particular section of an FM file. Any suggestions on what I should try?

    1. Hi Anh,

      Thanks for using the script. Kindly send me some sample files so that i can isolate the issue.

      Thanks,
      Bharat Prakash
      FrameMaker Engineering

  6. Thanks for the example. It works beautifully.

    Are there any tips on how to add a paragraph tag first? I have several tables in the doc that were copied in and have been assigned the standard “Table” format. So, in order to change the format, I would first have to add this format to the catalog. Any tips would be greatly appreciated. I’m trying to make the most of this new tool, but there’s not much reference material out there.

    Thanks!

    1. Hi Heather,

      Thanks for the feedback. Right now the script works on the tags already added to the catalog so if you are copying content from other files , the tags have to be added manually.

      Better method would be Importing formats between documents through File>Import>Formats…

      Hope this helps. Kindly let me know if you have any more questions.

      Thanks,
      Bharat Prakash(bharatp@adobe.com)
      FrameMaker Engineering

    1. Hi Michael,

      I have updated the samples files to FM10 version. I have also fixed the bug regarding not being able to type lowercase u letter.
      Kindly download the files now(Same link) and try running them.

      Thanks,
      Bharat Prakash

Leave a Reply

Your email address will not be published. Required fields are marked *