9 Replies Latest reply: Dec 30, 2013 8:54 AM by rombanks RSS

    event-driven extendscript

    rombanks Community Member

      Guys,

       

      I wonder if there is there a way to make a script event-driven, so that it will be triggered, for example, after importing formats from another file? The FM help says that 'Registered' scripts are event-driven, but there is not even a word on how to define the event.

       

      Thank you for your response in advance!

       

      My best wishes,

      Roman

        • 1. Re: event-driven extendscript
          frameexpert Community Member

          I wrote a blog post on this: http://frameautomation.com/?p=299

           

          Please let me know if you have any questions or comments. Thanks. Rick

          • 2. Re: event-driven extendscript
            rombanks Community Member

            Hi Rick,

             

            First of all, thank you very much for a detailed introduction to event-driven scripts!

            Now, I also know that you have a blog, which is great.

             

            I do have a couple of questions.

             

            1. It not clear to me how to add a "Registered" script to the FM script  catalog. This option is not documented well. The FM help says that adding a script as registered is described "in the appendix", which does not exist.

             

            2. In the sample script you presented on your blog, the following line is not defined anywhere else. How does this work?

             

            Notification (Constants.FA_Note_PostGenerate, true);

             

            3. function Notify (note, object, sparam, iparam) has 4 params, but only 2 of them are actually used. Why do you need to use "object" and "sparam" in this function?

             

            4. When running the command code checking script, and then importing formats from another file, I get [Object InvalidObject] alert and not the command number. Please, advise!

             

            5. Why would the Notify event be actually called twice?

             

            Thank you a million! You are great!

             

            My best wishes,

            Roman

            • 3. Re: event-driven extendscript
              frameexpert Community Member

              1. You have to "Run" the script to get it Registered. After you run it (or set it up as Autorun), it will show up in the Registered View of the Script Library palette.

               

              2. This is a built-in FrameMaker ExtendScript function.

               

              3. Different notifications may use different parameters. For example, FA_Note_PostSaveDoc will set sparam to the file name of the file that was just saved. The object is useful if you need to pass it to a function. For your script, object will be the Doc object of the target document. If you don't need a particular parameter in your script, just ignore it.

               

              4. You should post your code so we can take a look. I tested mine and I get the command number.

               

              5. I don't know; this may be a bug.

              • 4. Re: event-driven extendscript
                rombanks Community Member

                Hi Rick,

                 

                Thank you for your response!

                 

                 

                1. For some reason, not all scripts become "Registered" when run. For example, your command code checking script becomes Registered when run. The Apply Master Pages script posted by Jang in the previous discussion works fine but is not added to "Registered" when run. I don't understand what the difference is. If added to Autorun, a script will appear under Autorun and not under Registered, as far as I can see.

                 

                2. OK, thank you!

                 

                3. Got it, thanks!

                 

                4. I tested yours and got "[Object InvalidObject]". BTW, I'm using FM 10, in case this matters.

                 

                5. I see. But how did you discover that the function is triggered twice?

                 

                Thank you again!

                 

                My best regards,

                Roman

                • 5. Re: event-driven extendscript
                  frameexpert Community Member

                  1. You have to make sure that your setupNotifications (); call is at the top of the script outside of any functions, etc. Otherwise, it won't be called when you run the script.

                   

                  4. I am using FrameMaker 11. I just tried it with FrameMaker 10 and also get [Object InvalidObject]. Let me see if I can figure out a workaround.

                   

                  5. Because 790 (or [Object InvalidObject]) is displayed twice.

                  • 6. Re: event-driven extendscript
                    rombanks Community Member

                    Thank you, Rick!

                    I wonder if FM 11 uses different APIs.

                     

                    My best regards,

                    Roman

                    • 7. Re: event-driven extendscript
                      rombanks Community Member

                      Hi Rick,

                       

                      Just for a test, I tried using FA_Note_PostGenerate in the command code checking script. The result I got after updating a book was 0. This looks suspicious to me. What number do you get in FM11?

                       

                      Thanks!

                      Roman

                      • 8. Re: event-driven extendscript
                        frameexpert Community Member

                        Zero is probably correct for this event because the parameter isn't needed. When an event is specific like this one, you usually won't need to test the iparam or sparam parameters. For general events like FA_Note_PostFunction, any number of commands will trigger it, so you need to test iparam to see which one did.

                        • 9. Re: event-driven extendscript
                          rombanks Community Member

                          Hi Rick,

                           

                          Thank you for your response!

                          Did you have a chance to look into the FA_Note_PostFunction issue in FM10? I see that this event is mentioned in the FM10 FDK Guide, so it should be supported.

                           

                          Thank you!

                          Kind regards,

                          Roman