4 Replies Latest reply on Feb 14, 2015 2:03 AM by K.Daube

    Saving (and reading) RTF

    K.Daube Level 1

      Dear all patient helpers,

      My current project is 're-furbishing' the FameMaker to EndNote' connection. This task comprises several steps:

      1. Collect temporary citations (such as [Daube, 1969, #123] ) from text, footnotes and tables into an array. This part already works fine (I had to postpone further development for a year now...).
      2. Then I write this data to a new document (which is created from the template) - with your help this came to work today.
      3. This file then is saved as rtf to be worked off by the bibliographic application EndNote (or Citavi in another case) to resolve the temporary citations into formatted citations and the bibliography.
      4. After that the modified rtf is opened as an FM docment. The information from this is used to replace the  temp. citations in the user-document/book by the formatted citations.
      5. The user then copies the bibliography (as text only) into his appropriate chapter/section and formats it to his liking.

      For step 3 I have now researched a lot and found this:

      • app.ExportFilters does not provide the list of filters as stated in the FM Scripting Guide.
      • For FrameScript Johannes Graubner wrote:
        SAVE Document DocObject (docVar) File(ofilename) FileType(SaveFmtFilter) FilterFormatID('RTF');
      • Talking about filetype hint strings the FDK Programmers Guide (FDK-PG) informs that format ID would be ‘RTF ‘. But how to use this in eScrpt?
      • The Filetype hint string syntax in FDK-PG gives some information, but what vendor code shall be used for RTF?
      docId = F_ApiGetId(0, FV_SessionId, FP_ActiveDoc);
      params = F_ApiGetSaveDefaultParams();
      i = F_ApiGetPropIndex(&params, FS_FileType);
      params.val[i].propVal.u.ival = FV_SaveFmtFilter;
      i = F_ApiGetPropIndex(&params, FS_SaveFileTypeHint);
      params.val[i].propVal.u.sval = F_StrCopyString((StringT)"0001ADBEHTML");
      • At another place () Hint strings for the standard installation of filters) FDK-PG states: Microsoft RTF => 0001AW4W0191
      • Another information can be found on RTF 1.6 filter hint revealed! : '0001ADBIRTF '

      So my interpretation of all this leads to this snippet:

      var file = app.ActiveDoc;
      SaveFileRTF (file);
      function SaveFileRTF (file) {    
        var params = GetSaveDefaultParams();
        var returnParamsp = new PropVals();
        var i;
        i = GetPropIndex (params, Constants.FS_FileType);
        params[i].propVal.ival = Constants.FV_SaveFmtFilter;
        i = GetPropIndex (params, FS_SaveFileTypeHint);
        params[i].propVal.ival = "0001ADBERTF ");
        file.Save(file.Name, params, returnParamsp);

      But alas, this reports a stange error: "Semicolon expected on line 13". Even If you help me to overcome this the next swamp lurks in step 4: how to open  the RTF?

        • 1. Re: Saving (and reading) RTF
          K.Daube Level 1

          Ah, at least line 12 should read

          i = GetPropIndex (params, Constants.FS_SaveFileTypeHint);

          And after spotting the superfluous ) at the end of line 13 - no error occurs,

          but the script does nothing to an open/active doc

          So what is missing?



          I notice that properties are starting lower case in the FM Object Reference.

          So I change line 15 from

          file.Save(file.Name, params, returnParamsp);


          file.Save(file.name, params, returnParamsp);

          But that has no effect.

          Concerning the syntax

          Using the FrameMaker 12 Ob ject model (chm) from Jongware as of 18-Jan-2015) i see this (the FM devnet is aged with FM10 scripting guide etc., however FrameMaker Support Center leads to the FrameMaker Learn & Support with the FM-12 Scripting Guide)

          - In the FrameMaker 12 Object Reference properties start upper case (e.g. CurrentPage)

          - Same is true for the methods there:  AddText

          - In the JS base classes properties start lower case (e.g. absoluteURI)

          - Same is true for the methods there: concat

          - For the Script UI classes the properties start lower case (e.g. parent)

          - And the methods also start lowe case (e.g. drawOSControl)

          IMHO this is more than tricky.

          • 2. Re: Saving (and reading) RTF
            frameexpert Level 4

            Hi Klaus, This works for me in FrameMaker 12. Please let me know if you have any questions or comments. -Rick


            #target framemaker
            var doc = app.ActiveDoc;
            saveRtf (doc);
            function saveRtf (doc) {
                var saveName, saveParams, retParams, i = 0;
                // Get a property list to return any error messages.
                retProps = new PropVals();
                saveProps = GetSaveDefaultParams();
                i = GetPropIndex (saveProps, Constants.FS_FileType);
                saveProps[i].propVal.ival = Constants.FV_SaveFmtFilter;
                i = GetPropIndex (saveProps, Constants.FS_SaveFileTypeHint);
                saveProps[i].propVal.sval = "0001ADBIRTF ";
                saveName = doc.Name.replace (/\.[^\.]+$/, ".rtf");
                doc.Save (saveName, saveProps, retProps);
            • 3. Re: Saving (and reading) RTF
              frameexpert Level 4

              The key here is on line 17. Since the file hint is a string you have to use sval instead of ival. ival would indicate an integer data type; sval is a string.

              • 4. Re: Saving (and reading) RTF
                K.Daube Level 1

                Thanks Rick!


                Compared to my code the difference is in providing the extension rtf in the file name. The sval was there already.

                Hence my other test with a hardcoded target file name (containing that rtf) worked, but not the 'flexible' script.

                I still have to learn to more carefully compare go and nogo situations...