6 Replies Latest reply on Jan 19, 2015 8:15 AM by 4everJang

    Setting property ssval

    4everJang Level 3

      Hello fellow scripters,

       

      I am trying to get a script include a TOC in a generated book. I can add the new BookComponent (copied from a template file) as a TOC, set it to generatable and include it in the update process, but all I get is an empty TOC, as the ExtractTags property of the new BookComponent is not set. I tried to set this property by passing it a string array but that action is completely ignored. Then I got the propVals array and tried to set the property there, then pass back the propVals. That is where FM12 hangs up and I have to restart it to become responsive again.

       

      This is the piece of code I am using:

       

      oaProps = oComp.GetProps ( );
      i = GetPropIndex ( oaProps, Constants.FP_ExtractTags );
      oaProps[i].propVal.ssval.push ( "Title_0" );
      oaProps[i].propVal.ssval.push ( "Title_1" );
      oaProps[i].propVal.ssval.push ( "Title_2" );
      oComp.SetProps ( oaProps );

       

      Maybe I am doing something illegal here but the local copy of my properties does show the strings as I push them into the ssval array. There must be a specific way to set these strings array propVals but there is no documentation about it. Does anyone have experience with this ?

       

      Thanks

       

      Jang

        • 1. Re: Setting property ssval
          frameexpert Level 4

          Hi Jang, Are the paragraph formats you are including in your ExtractTags array in the book's first component? I have found that you sometimes have to make sure they are in the first component and update the book before the ExtractTags property of the TOC will work. I am not sure why this is, but I think it mimics what happens in the interface. When you add a TOC component "by hand" and set up the Include formats, it will only show the formats that are in the first component in the book. -Rick

          • 2. Re: Setting property ssval
            4everJang Level 3

            Hi Rick,

             

            Yes, the formats are available. As I mentioned, Frame hangs when I try to run SetProps after adding anything to the ssval strings array in that one property. I have now tried to do something that should definitely work, but it gives the same result.

             

            oaProps = oComp.GetProps ( );

            oComp.SetProps ( oaProps );

             

            It hangs on the last line. Obviously, this is not as it is suppoed to be. I will file a bug report and see what the Adobe guys can tell me.

             

            Ciao

             

            Jang

            • 3. Re: Re: Setting property ssval
              frameexpert Level 4

              Hi Jang, Did you try setting the ExtractTags property directly without using a property list? This works for me with the TOC component selected:

               

              #target framemaker
              
              var book = app.ActiveBook;
              var bookComp = book.FirstSelectedComponentInBook;
              
              var extractTags = bookComp.ExtractTags;
              extractTags.push ("Heading1");
              
              bookComp.ExtractTags = extractTags;
              
              • 4. Re: Re: Setting property ssval
                4everJang Level 3

                Hi Rick,

                 

                I though I had already tried that one, but it did not work. I have given it another try and found something really strange, which explains something about the scripting wrappers implementation. We are, after all, learning by doing, as the official reference is not all that good.

                 

                Here is what I tried before:

                 

                var saTags = [ "Title1", "Title2", "Title3" ];

                oBookComp.ExtractTags = saTags;

                 

                Guess what? There is no change whatsoever, not even if the ExtractTags property was an empty array previously. But with your code it does work. It seems that when creating a string array by the line

                 

                var saTags = oBookComp.ExtractTags;

                 

                what really happens is that a pointer to the string array is returned, not the string array itself. And when passing the argument back to the property it must still be the same pointer to the string array, which is probably possible in ExtendScript but a lot harder to do. Replacing the existing string array in the propVal is not possible, apparently. The code wrapper for ExtendScript for a string array (ssval) is really strange and its handling is not documented anywhere.

                 

                Anyway, thanks for the help. I will of course still file the bug, as Frame should not simply hang when I try to use a perfectly legal (according to the documentation) method.

                 

                Ciao

                 

                Jang

                • 5. Re: Re: Setting property ssval
                  frameexpert Level 4

                  Yes, I tried creating an array first like you did, but it didn't work for me either. The clue for me was to run this:

                   

                  alert (bookComp.ExtractTags.constructor.name);

                   

                  which returned "Strings". I am not sure how to create this data type directly, so I did it indirectly in line 06. To see if it had a Push method, I did this:

                   

                  alert (bookComp.ExtractTags.reflect.methods);

                  • 6. Re: Setting property ssval
                    4everJang Level 3

                    Guess what? It is even crazier than I thought it was.

                     

                    I thought I could skip the code lines that apparently copy the strings array to a local one, and push it back when I have added or changed the contents. So I tried pushing strings in to the ExtractTags property of the BookComponent directly. That has no effect whatsoever. It only works when you pull the strings array into a local strings array (instead of creating a fresh one), then manipulate the local copy and then push it back.

                     

                    Why this is the case is beyond my understanding. When I find out I will share it with you guys.

                     

                    Ciao