1 Reply Latest reply on Nov 18, 2011 3:38 PM by OliverJohn

    UpdateBook

    Jason L-S Level 1

      Hi,

       

      I'm a newbie :-)

       

      Could someone please post an example of how to update a book using the UpdateBook method?

       

      This would be a useful starting-point for explaining how to work with PropVals, I think.

       

      If you do not do this the correct way, you can crash FrameMaker. Guess how I know?

       

      The PropVals thing is what's got me stumped. According to the scripting guide: "Note: Always initialize the pointer to the property list that you specify for updateReturnParamspp to null before you call UpdateBook().

      To get a property list to specify for the updateParamsp parameter, use GetUpdateBookDefaultParams() or create the list from scratch."

       

      That's what I don't really understand.

       

      Thanks!

       

      Jason

        • 1. Re: UpdateBook
          OliverJohn

          Short answer first:

           

                    var bk = app.ActiveBook;

                    var updateParams = GetUpdateBookDefaultParams();

                    var retParams = AllocatePropVals (1);

                    bk.UpdateBook (updateParams , retParams);

           

          Longer answer:

           

          Learning to wrap your head around "the PropVals thing" is probably the single steepest part of the FM scripting learning curve, esp. if you come from a JavaScript background. The PropVals object is how FM represents many types of property lists.

           

          The object itself is an array of PropVal objects. Each PropVal has two main properties: a propIdent number, which identifies what the property is, and a TypedVal object called propVal, which holds the value for that property.

           

           

          Each propVal has a property called valType, which identifies a datatype. What other properties the TypedVal has is dependant on the datatype, e.g., sval for strings, ival for signed intergers.

           

          So if we go back to updating your book--we could modify the default parameters to skip updating XRefs like this:

           

                    var bk = app.ActiveBook;

                    var updateParams = GetUpdateBookDefaultParams();//Returns the array of PropVals

                    var retParams = AllocatePropVals (1); //"initializes the pointer"

                    var xProp = GetPropIndex (updateParams, Constants.FS_UpdateBookXRefs);

                    updateParams[xProp].propVal.ival = false; //ival = 0 would mean the same thing

                    bk.UpdateBook (updateParams , retParams);

           

          Several of the other threads on this board can provide more examples of working with PropVals. You can see my struggles with this subject here.