Skip to main content
frameexpert
Community Expert
Community Expert
May 7, 2014
Question

Scripting tips

  • May 7, 2014
  • 3 replies
  • 3306 views

Hi Scripters, I want to offer some advice to those seeking scripting help. First of all, this forum isn't too busy, but there are some extremely helpful people on here. If you follow this advice, it will make it easier for willing people to help you.

One of the most important things you can do when solving a scripting problem is to isolate the problem to the smallest possible unit. For example, if you are solving a problem with tables, don't post code that processes all of the tables in the document. Isolate the code so it just works on the selected table. Or, if you are trying to apply a condition format to paragraphs, don't post all of the code for processing all of the components in a book. Instead, isolate your code to work on a single, selected paragraph. When code is isolated to small units like this, it makes it easier to test and troubleshoot. And when it doesn't work, it makes it easier for other people to stage things on their computers so they can see what is wrong.

In general, this is the best way to develop scripting solutions anyway. When your individual "units" are tested and debugged, you can expand the code out to process an entire document or book. As an added benefit, your code becomes more modular and easier to reuse in other scripts. I will try to follow up with some specific code examples so you can see how it works. Please let me know if you have any questions or comments. -Rick Quatro

This topic has been closed for replies.

3 replies

DaitecFMTeam
Participant
April 13, 2018

Hi Rick, and anyone else listening!

I hope I'm not being bothersome, but can you point to resources with good information on FrameMaker scripting?

The documentation provided by Adobe is woefully lacking. (Documentation doesn't match what I observe in ExtendScript, hundreds of constants just listed with no explanation...)

If there's no such thing, I'll post as needed, but if there is, I could solve some basic problems without having to do the forums.

Thanks in advance!

4everJang
Legend
April 13, 2018

There is no such resource, as there has not been a market for such a resource. Just like Rick and several other scripting pros, I have learned scripting the hard way - by trail and error and lots of time looking up the properties and methods in the Scripting Guide. Even if you would find some basic how-to on ExtendScript in general, you would not find the real value there - which is a thorough understanding of all the objects and methods available in FrameMaker, and how FrameMaker handles them.

We started using FrameScript and/or Visual C++ in the FDK before ExtendScript arrived (in Fm 10) and could transfer all our FrameMaker knowledge to the new language without any problem. Prepare to spend lots of time over several years if you want to become an experienced FrameMaker scripter.

Until that time, the forum is your best resource. Work your way through past posts - even the ones that do not seem to have any bearing on your current problem - and you will pick up essential knowledge. Bu be aware that just copying ready-made code from posts does not help in learning how to handle it. Always try to make changes to the code offered on the forum and see where you break it. That is where you learn.

Good luck.

4everJang

frameexpert
Community Expert
Community Expert
May 7, 2014

Here is a good place to start. Someone recently asked for help applying a condition format to certain paragraphs. When working on paragraphs, first get your code working on the paragraph containing the insertion point. Here is a useful snippet for doing that:

// Set a variable for the active document.

var doc = app.ActiveDoc;

// Get the paragraph at the beginning of the selection or insertion point.

var pgf = doc.TextSelection.beg.obj;

// Do something with the paragraph here:

// ...

Here is code you can use for working on the selected table, or the table containing your text cursor:

// Set a variable for the active document.

var doc = app.ActiveDoc;

// Get the table currently selected or that contains the insertion point.

var tbl = doc.SelectedTbl;

// Do something with the table here:

// ...

Do you need to work on table cells? Here is how to isolate the cell object that contains your text cursor.

// Set a variable for the active document.

var doc = app.ActiveDoc;

// Get the paragraph that contains the insertion point.

var pgf = doc.TextSelection.beg.obj;

// Get the table cell that contains the paragraph.

var cell = pgf.InTextObj;

// Do something with the cell here:

// ...

Or, find the row that contains the cell where your text cursor is:

// Set a variable for the active document.

var doc = app.ActiveDoc;

// Get the paragraph that contains the insertion point.

var pgf = doc.TextSelection.beg.obj;

// Get the table cell that contains the paragraph.

var cell = pgf.InTextObj;

// Get the row that contains the cell.

var row = cell.CellRow;

// Do something with the row here:

// ...

www.frameexpert.com
May 13, 2014

Thank you for the helpful suggestions, Rick. I'm new to scripting, as you know, so helpful tips are very appreciated!

Arnis Gubins
Inspiring
May 7, 2014

Hi Rick,

Great advice. I'll also add that posters should mention which version of FM that they are using and what platform they are running on. [Older versions of Extendscript had numerous issues]

Also, for those reading this thread for the first time, please use the "Correct Answer" link when your problem has been solved so that others can be see that a solution exists and to give credit to who helped you out.