12 Replies Latest reply on May 20, 2010 10:41 AM by zak.nelson

    ExtendScript function return values

    Harbs. Adobe Community Professional & MVP

      As far as I can tell, it's only possible to run ExtendScript functions from a CS Extension. I don't see any (straight-forward) way get the return value of an ExtendScript function.

       

      CSXSInterface.getInstance().evalScript() does not seem to return any useful information. Am I missing something, or should I make a feature request?

       

      Harbs

        • 1. Re: ExtendScript function return values
          Maria J Gutierrez

          Hi Harbs,

           

          The CSXSLibrary refrence API for the evalScript() call in the CSXSInterface shows you a sample of how you can pass back an object or xml back to the extension and how to read it in ActionScript.

           

          The information you return is stored in the data attribute of the SyncRequestResult object that evalScript returns.

           

          Let me know if that answers your question.

           

          Maria

          1 person found this helpful
          • 2. Re: ExtendScript function return values
            Harbs. Adobe Community Professional & MVP

            Hi Maria,

             

            Hmm. I missed that example. I'll have to take a better look.

             

            Maybe you can explain why my test did not work?

             

            I created an ExtendScript function:

             

            function Test(){

            return "bla bla";

            }

             

            In my ActionScript code I did:

            var result:SyncRequestResult = CSXSInterface.getInstance().evalScript("Test");

             

            I put a breakpoint on the following line, and the result.data was useless.Why?

             

            Thanks

            Harbs

            • 3. Re: ExtendScript function return values
              Maria J Gutierrez Level 1

              Hi Harbs,

               

              No problem.

               

              I believe this is not working because you are passing a string back that is not formatted as an object or XML string. ActionScript in this case expects a string that can be parsed into an object (external API XML format) or an XML document. I think passing your plain string is causing some internal error.

               

              Try something like this:

               

               

               

              The data attribute will return the XML. Then you can parse it as it suits.

               

              Hope this helps.

               

              Maria

              1 person found this helpful
              • 4. Re: ExtendScript function return values
                Harbs. Adobe Community Professional & MVP

                I must be doing something wrong, because it's still not working...

                 


                Here's my ExtendScript:

                 

                function test1(){
                alert(1);
                return "bla bla";
                }
                function test2(){
                alert(2);
                    return{
                        text:"bla bla",
                        number:1
                    }
                }
                function test3(){
                alert(3);
                    return
                        <bla>
                            <ble/>
                            <ble>
                                <blu/>
                            </ble>
                        </bla>
                }
                

                 

                Here's my ActionScript:

                 

                            var result1:SyncRequestResult = CSXSInterface.getInstance().evalScript("test1");
                            var result2:SyncRequestResult = CSXSInterface.getInstance().evalScript("test2");
                            var result3:SyncRequestResult = CSXSInterface.getInstance().evalScript("test3");
                
                

                 

                and here's what I'm seeing in the debugger:


                2010-05-17_2155.png

                 

                I am getting all three alerts, so I know that the functions are being run...

                 

                Harbs

                • 5. Re: ExtendScript function return values
                  Bob Stucky Adobe Employee

                  Hey Harbs,

                   

                  Try:

                   

                  function test1() {

                       alert( "howdy" );

                       return '<object><property id="bla"><string>blah blah blah</string></property><property id= "numb"><number>42</number></property></object>';

                  }

                   

                  You have to serialize the return object to an Xml STRING, and it must be in the above format (to get an object back in the data property of the SyncRequestResult). You can't send back an object directly. It won't automatically put it in the xml format shown above.

                   

                  You can also just send back an arbitrary xml block.

                   

                  Bob

                  • 6. Re: ExtendScript function return values
                    Harbs. Adobe Community Professional & MVP

                    Duh! <smacks forehead!>

                     

                    Thanks!

                     

                    Harbs
                    • 7. Re: ExtendScript function return values
                      Harbs. Adobe Community Professional & MVP

                      Do you happen to have a generic ExtendScript function to serialize objects and/or xml in your back pocket?

                       

                      Harbs

                      • 8. Re: ExtendScript function return values
                        Bob Stucky Adobe Employee

                        Nope, sorry.

                         

                         

                        Bob

                        • 9. Re: ExtendScript function return values
                          Harbs. Adobe Community Professional & MVP

                          Didn't think so, but it doesn't hurt to ask.

                           

                          I'll leave it as an exercise for some day when I'm bored...

                           

                          Harbs

                          • 10. Re: ExtendScript function return values
                            zak.nelson Level 3

                            Not in ExtendScript, but you may be interested to know we have a sample which demonstrates how you can persist AS objects. The sample is called CSXSPrefBase and is available via the remote samples in Extension Builder. The sample serializes AS objects using AMF, encodes the result in Base64Encoding, and then stores the data in CSXS's preference store for later retrieval.

                            • 11. Re: ExtendScript function return values
                              Harbs. Adobe Community Professional & MVP

                              Zak,

                               

                              Your cookbook post was exactly what I was looking for: http://cookbooks.adobe.com/post_Communicating_between_JavaScript_and_the_CS_SDK_us-17383.h tml

                               

                              HostObject.getRoot(HostObject.extensions[0]).myFunction();

                               

                              returns values in an infinitely more useful (or at least, easy to use) format!

                               

                              Harbs

                              • 12. Re: ExtendScript function return values
                                zak.nelson Level 3

                                Glad you liked it! Your point that HostObject returns more useful information is indeed true. The most compelling demonstration of this is passing complex objects back and forth. Say your ExtendScript function returns an InDesign document. You can reconstruct this document on the ActionScript side using the syntax:

                                 

                                var d:Document = new Document();

                                d.hostObjectDelegate = jsxInterface.getDocumentFromES();

                                 

                                It's a pretty powerful technique, one that is not currently possible using CSXSInterface. I've updated the recipe to include this information.