The second in a series of posts where I pretend to be a programmer.
FrameMaker really shines when you have a suite of large documents that all have to have matching formatting. You create one set of paragraph styles, one set of master pages, one set of reference pages, etc., then you import all the properties from your template into each document, and — Voila! — consistency across all.
In the ideal world, your set of formats never needs to be edited and never varies across your whole suite of documents. Of course, we don’t work in an ideal world, all sorts of things can conspire to ruin your perfect template, and one day you look at your paragraph catalog and you have a hundred styles when you only needed twenty. Maybe some of them came from those times you had to import documents from Word. Maybe others from that time the temp worked on your docs while you were on vacation. Maybe your boss asked for a new style for ideas that aren’t quite Notes but aren’t quite Warnings either.
But now, the only way to get rid of the extra styles is one-by-one using Delete Formats from Catalog. How tedious! And you have to do it for each of your documents, since the import function isn’t destructive.
If only there was a better way …
I know! Let’s write a script! If you’re not sanguine on dropping $150 on FrameScript, take a look at fmPython. fmPython is a Python wrapper for the FrameMaker FDK. It’s not in development anymore, and the documentation is pretty rough, but it’s worth a go for the occasional scripting need. You’ll need to install version 2.2.3 of Python to get fmPython to work.
Here’s the script I used:
import maker doc = maker.session.activeDoc goodstyles = ('Body Text', 'Heading 1', 'Heading 2', 'Heading 3', 'Heading 4', 'Numbered List-1', 'Numbered List-2', ) theformat = doc.firstPgfFmt done = False while not done: try: thenextformat = theformat.next except RuntimeError: done = True if not theformat.name in goodstyles: theformat.delete() if not done: theformat = thenextformat
goodstyles is a list (actually a tuple) of styles that you don’t want to delete. Edit the list so that it includes all of the styles you want to keep, using the same format.
To run the script:
- Paste the script into a blank FrameMaker document.
- Select Selection as Script from the fmPython menu in FrameMaker. If you don’t see the menu, you haven’t installed fmPython correctly.
- Open the document whose styles you want to prune.
- Select Execute Script from the fmPython menu.
The script doesn’t save the document, so if you deleted more than you wanted to, you can just revert to a saved version. If you want to play around with fmPython, you could fairly easily adjust the script to loop through all of the documents in a book.