Posts tagged "AIR"

Developing ExtendScripts – Part 2

If you are very new to ESTK, I suggest you to read the first blog entry in this series. In the first blog entry, we didn’t use any functions that are specific to any TCS component. In this blog entry we will. Let us develop a script that changes the DPI setting of all the images inserted in a FrameMaker document that is already opened. Before we start, let us logically divide our requirement:

The script should:

  1. refer to the currently active FrameMaker document.
  2. detect the first graphic in the document.
  3. change the DPI setting of the graphic.
  4. detect the next graphic.
  5. change the DPI setting of the graphic.
  6. continue step 4 and 5 until the script detects the last graphic.

Open FrameMaker, and then open ESTK. In ESTK, select FrameMaker from the drop-down list displayed on the upper-left corner. We didn’t do it when we created the script that displayed an alert, because the functions that we used to display an alert have nothing to do with any of the TCS component. Here, we are going to write a script that automates a task in FrameMaker. So, we will use some methods that are related to FrameMaker. Observe the green icon displayed. It represents that a FrameMaker session is alive. If we didn’t have opened FrameMaker, the icon would have displayed in red.

Let us start coding. First, we will refer to the active FrameMaker document. The code for this is:

document =app.Activedocument

The code creates a document variable pointing to the active FrameMaker document. app.Activedocument represents the currently active document. Now, let me introduce Object Model Viewer that comes handy when you develop scripts using ESTK. Press F1 or click Help > Object Model Viewer.

Click Browser, and then select FrameMaker 10 from the drop-down list beneath it. You will see all the TCS components you installed in this drop-down list. We selected FrameMaker 10, because we are trying to get information about a method in FrameMaker, app.Activedocument. Type the same in the text box displayed on the upper-left corner, and click Search. From the search results, clicking the link provides information about the method you clicked. This information is very helpful when you develop scripts. You can select the specific TCS component on which you need information and search for information.

Let us go back to coding. I am not going to explain each line of code, because I assume that you know the basics of scripting.

document =app.Activedocument
gobj = document.FirstGraphicIndocument;
       gobj = gobj.NextGraphicIndocument;
       if(gobj.type == FO_Inset)
            name = gobj.InsetFile;

To summarize, this is what the script does:

The code first creates a reference to the active document. Then, creates a reference to the first graphic in the document using the document.FirstGraphicIndocument method. It uses a while loop to detect all graphics in the document. The reference move to the next available graphic using the NextGraphicIndocument method and it continues till it reaches the last graphic. It uses the InsetDpi property of the graphic reference to set the DPI value.

Save the file and close ESTK. (Don’t ask me how.)

Let us run the script separately. We have already seen how to run the script in ESTK. Let us not run the script in ESTK. We will run the script through FrameMaker, because in real-time, you need not be the programmer who actually does the coding. So, you don’t need ESTK to run it. From FrameMaker, click File > Script > Run. Select the file we saved and click Open.

That’s it. To recap whatever we learned:

- Object Model Viewer helps you to get information about the methods that you can use in ExtendScripts.
- You don’t need to have ESTK to run ExtendScripts.