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.
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: // ...
Thank you for the helpful suggestions, Rick. I'm new to scripting, as you know, so helpful tips are very appreciated!
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!
1 person found this helpful
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.
1 person found this helpful
The best documentation for scripting FrameMaker with ExendScript is not the ExtendScript documentation, it is the FrameMaker FDK documentation. You should download the FDK just to get the two main PDFs; one is a User guide and the other is a Reference guide. The User guide is an overview (with examples) and of how to perform common automation tasks with the FDK. This document will give you a good feel for how to solve problems with the FDK, which is transferable to ExtendScript. The syntax of the ExtendScript properties and methods are very similar to the syntax of the FDK properties and functions so you can even use the C examples to help you with your ExtendScript code.
Here are three of my golden rules that will help you be successful:
1) Work with small units in FrameMaker when solving problems. For example, work on a single paragraph, cell, graphic, or whatever you are trying to manipulate. Don't try to do too much at once.
2) Make your code modular by using functions, which are easier to test, troubleshoot, and, most important, reuse.
3) Develop your skills by using them. The more you practice, the better you will get.
Thank you for the advice. I found the FDK documentation and it is indeed much more well documented.
I'll have a go through this.
If I run into more specific problems I'll try the forums again, but the FDK documentation looks like it will give me a decent jumping off point.
1 person found this helpful
Another useful resource which could help is the Extending FrameMaker blog by Debra Herman. Although it's not been updated for a while you will still find a lot of helpful ExtendScript Information.