Using a regular expression to convert an image name to a path

Mike and I started an interesting discussion about using ExtendScript to import images from a base file name that the user enters. One of the key tasks is to figure out how to take a base file name that uses their syntax and derive a full path from it. Based on Mike’s examples, I came up with the following ExtendScript function:

alert (getImagePath ("MSP4321"));

function getImagePath (imageName) {

  var regex = /([A-Z]{3})((\d)\d)(\d\d)/;
  var path = "\\\\server\\Graphics\\$1\\$1$3000-$3999\\$1$200-$299\\$1$2$4.pdf";

  if (imageName.search(regex) !== -1) {
    return imageName.replace (regex, path);
  } else {
    return null;
  }
}

This function illustrates the power of regular expressions. The basic regular expression is this:

Find 3 uppercase letters: [A-Z]{3}

followed by four digits: \d\d\d\d

The parentheses “capture” parts of the match and put them into special variables in the form of $#, where # is a number from 1 to 9. To figure out what number goes with what set of parentheses, you start counting from the left. So, in our regular expression

([A-Z]{3}) will be $1. In our example, this will be MSP.

((\d)\d) will be $2. In our example, this will be 43.

(\d) nested in $2 will be $3. In our example, this will be 4.

and (\d\d) will be $4. In our example, this will be 21.

We can use these variables to build up our path. Notice the $# variables in the replacement string (color-coded for clarity):

"\\\\server\\Graphics\\$1\\$1$3000-$3999\\$1$200-$299\\$1$2$4.pdf"

This will become

"\\\\server\\Graphics\\MSP\\MSP4000-4999\\MSP4300-4399\\MSP4321.pdf"

The backslash in JavaScript is an escape character, so to get the literal backslash character, we have to use 2 where we want 1.

Copy the function into the ExtendScript Toolkit and try a few filenames that use this format, and you will get the correct path every time. Regular expressions are a deep topic, but as you can see, they are very powerful for parsing tasks like this.

-Rick

FrameMaker 10 ExtendScript: The Object Model

Thank you to all that attended this webinar. I will post the link to the recording as soon as it is available. In the meantime, here is a link to the FrameMaker Object Model chm file and webinar slides:

http://www.rickquatro.com/resources/FM10_ObjectReference.zip

Here is a link to the FrameMaker 10 FDK:

http://www.adobe.com/devnet/framemaker.html

After you install it, the documentation will be in the docs folder.

Arnis asked about dumping a list of properties for an object. In FrameScript it is easy:

Set oDoc = ActiveDoc;
// Write the properties to the Console.
Write Console oDoc.Properties;

With ExtendScript, you can use a function; in this case, I am writing to the JavaScript Console instead of the FrameMaker Console:

var doc = app.ActiveDoc;
writePropsToConsole (doc);

function writePropsToConsole (object) {

  for (var name in object) {
    // Write the properties to the JavaScript Console.
    $.writeln (name + ": " + object[name]);
  }
}

Please let me know if you have suggestions for future webinars. Thanks again for all your support.

-Rick

ExtendScript Webinars: What Do You Want to Learn?

I just finished my second FrameMaker 10 ExtendScript webinar, which I enjoyed immensely. The first one was done in conjunction with Adobe, the second was sponsored by Carmen Publishing Inc. I would like to do more ExtendScript webinars and want to know what topics people are interested in. Please leave comments with suggestions for ExtendScript topics. Thank you very much.

-Rick

In Memory of Bruce Foster

Bruce Foster, creator of many fine FrameMaker plugins, passed away suddenly on Saturday, June 11, 2011. Although Bruce had been diagnosed with multiple myeloma in September 2010, his death still came earlier than was expected. Bruce’s plugins for FrameMaker were BookInfo, ImpGraph, MifSave, MifToFM, RtfSave, and his most famous, Archive.

Bruce’s website is now offline and, as far as I know, his plugins are no longer available  for sale.

Adobe Engineering has just released a free ExtendScript script for archiving FrameMaker 10 books:

http://blogs.adobe.com/techcomm/2011/07/create-a-book-packager-using-extendscript.html

I haven’t tested the script yet, so I can’t necessarily recommend it, but it is certainly worth looking at.

– Rick

Autonumber Problems

Here is part of a recent post on the Framers list:

Single-file doc with four Sections. Sections and sub-sections numbered 1, 1.1, 1.1.1 etc.

Pgf numbering formats:

Heading1 S:<n+>.< =0>< =0>< =0>
Heading2 S:<n>.<n+>< =0>< =0>
Heading3 S:<n>.<n>.<n+>< =0>

But I’m getting Sections 1 and 2 (with subsections), then 5 and 6 (which should be 3 and 4)….Pix and tables are numbered with F:<n+> and T:<n+> respectively so shouldn’t be affecting anything.

Autonumbering in FrameMaker is one feature that is rock-solid. So these problems are always caused by intervening paragraphs that have unintended autonumber counters. The trick is finding the offending paragraphs. I use a FrameScript script to make an “autonumber report” of a document or book. With this report, the cause of autonumber problems can be quickly found.

The author of the Framers post sent me the problem document and in seconds I generated the following spreadsheet (click the image to see it full size):

It’s pretty easy to see the problem paragraphs, which I have highlighted. The key to finding them is to look for the last good number, which is in row 13. Next, look for the first bad number, which is in row 20. Now we know that the problem paragraph or paragraphs is between these two rows in the spreadsheet. At this point, it’s best to scan the Autonumber String column, and look for the S: series label, which brings us to rows 15 and 17.

As it turns out, in this document the two offending paragraphs were very small and at the top of the page, which is why they were difficult to find. But like many other tasks, FrameScript makes it easy. If you are interested in purchasing this script, please let me know. Thank you very much.

– Rick

Lining up a Table Across Columns

This question comes up from time-to-time on the FrameMaker lists, so I will illustrate the problem and solution with four screenshots. You have a single table anchored in a paragraph in the left column. As the table flows from column-to-column, the top of the table in the first column does not line up with the top of the table in the rest of the columns.

To remedy this, you need to change settings in two dialog boxes. First, click in the anchor paragraph and bring up the Paragraph Designer. Change the Line Spacing to 0 points and the Space below to -2 points and click Update All. Go to the Default Font area of the Paragraph Designer, set the Font Size to 2 points, and click Update All (not shown in the screenshot). You won’t see a change until you do the next step.

Click in the table and open the Table Designer. Change the Space Above to -2 points and click Update All.

The table tops in all of the columns will now line up with each other.

Setting Acrobat Bookmarks for a Book

When you save a FrameMaker book to PDF, you are presented with the PDF Setup dialog box, where you can set which paragraphs (or elements) you want to appear as bookmarks in the PDF. Often, you will set the Include formats and levels just how you want them, but when you make the PDF, one or more paragraphs will be included that you didn’t specify. In fact, these paragraphs won’t show up in the Include/Don’t Include lists in the PDF Setup dialog box. Scott Prentice, in a recent framemaker-dita@yahoogroups.com post, gives the reason behind this:

In my testing, I believe that the key factors are that the first file in the book needs to have definitions for all of the para styles in the book, and you have to set the include/exclude values on that file. If it’s a binary file, these settings would be made there … if it’s structured, you’d need to make those settings in the template that’s applied to that component. Continue reading “Setting Acrobat Bookmarks for a Book”

Fun with Acrobat Forms

I have created a great workflow for developing Acrobat forms, using FrameMaker, FrameScript, and TimeSavers from MicroType (http://www.microtype.com). Using this workflow makes it practical to use FrameMaker to develop PDF forms. FrameMaker’s graphic and table features can be used to layout great looking forms, while TimeSavers eliminates nearly all of the required Acrobat post-processing. A set of FrameScript scripts streamlines the insertion of the TimeSavers markers in the FrameMaker documents.

If you have a need for Acrobat forms, or are interested in the process, please let me know. I will be glad to provide a demonstration of the process. Also, I am soliciting a few more forms to do for free that I can use for demonstration purposes. If you have a forms that you would like converted to Acrobat forms, please let me know. In the meantime, take a look at some of the forms I have developed using FrameMaker, FrameScript, and TimeSavers:

http://www.rickquatro.com/forms/ClientQuestionnaire.pdf
http://www.rickquatro.com/forms/LosersAreWinners_Men2.pdf
http://www.rickquatro.com/forms/LosersAreWinners_Women2.pdf

-Rick

Renaming DITA Map Topics

I have a client using MIF2Go to generate DITA from unstructured FrameMaker documents. They are very happy with the entire process with one exception: They want an easy way to rename the href values in the DITA map, and the corresponding topics on disk. I have proposed a set of FrameScript scripts that will automate the process. The script proposes new topic names, based on the topicref’s navtitle value. You can have the script automatically use the new names, or you can use a “semi-automatic mode” where the old names and proposed new names are written to and Excel file. Then you can use Excel to fine-tune the new names. A second script quickly applies the spreadsheet names to the DITA map and corresponding topic files.

You can take a look at the documentation here. The cost for the set of scripts is $95 US. To purchase the scripts, please contact rick@frameexpert.com.

–Rick

Move Markers to the Beginning of Words

Maxwell Hoffman recently posted “Top 10 mistakes FM Uses make in content before translation” on his blog (www.tinyurl.com/gpi-fm1). One of the mistakes is having markers within words instead of at the beginning of words. I decided that this could be solved quickly and easily with a FrameScript script. You can download the free script at
http://frameautomation.com/MoveMarkers.zip. It will process all of the markers in the active document or book, allowing you to solve the problem in seconds. Instructions are in the included ReadMe.text file. If you need to purchase FrameScript licenses, please contact me for discount prices. Please let me know if you have any questions or comments.

–Rick