8 Replies Latest reply on Apr 16, 2018 8:24 AM by Ian Proudfoot

    Scripting tips

    frameexpert Level 4

      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

        • 1. Re: Scripting tips
          Arnis Gubins Adobe Community Professional & MVP

          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.

          • 2. Re: Scripting tips
            frameexpert Level 4

            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:
            // ...
            
            • 3. Re: Scripting tips
              snipppyBishop Level 1

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

              • 4. Re: Scripting tips
                DaitecFMTeam Level 1

                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!

                • 5. Re: Scripting tips
                  4everJang Level 3

                  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

                  1 person found this helpful
                  • 6. Re: Scripting tips
                    frameexpert Level 4

                    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.

                    1 person found this helpful
                    • 7. Re: Scripting tips
                      DaitecFMTeam Level 1

                      Rick, 4everJang,

                       

                      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.

                       

                      Thanks again!

                      • 8. Re: Scripting tips
                        Ian Proudfoot Adobe Community Professional

                        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.