2 Replies Latest reply on Jul 2, 2013 6:23 AM by David A Koot

    Changing the text inset's source file with a script

    David A Koot

      I'm looking for a way to replace an existing text-inset in a document with the contents of an other file (by reference), by means of scripting. Say, I have a document c:\referer.fm, in which there is a text inset of which the source file is: c:\A.fm

      I also have c:\B.fm, and now I want to change referer.fm so that no longer the text inset holds the text from A.fm, but from B.fm.

       

      I tried this:

       

      var doc = app.ActiveDoc;

      var textinset = doc.FirstTiInDoc;

      var pathtosource = textinset.TiFile;

      pathtosource = "c:\B.fm";

      textinset.UpdateTextInset();

       

      But this doesn't work. I guess setting 'pathtosource' cannot be done this way. If anyone knows the way to do this, I would really appreciate your help!

       

      David

        • 1. Re: Changing the text inset's source file with a script
          4everJang Level 3

          Hello David,

           

          You are not manipulating the text inset but a copy of the text inset's filename. Your parameter "pathtosource" is a local copy of the property you read from the actual text inset.

           

          Try this code instead:

           

          var doc = app.ActiveDoc;

          var textinset = doc.FirstTiInDoc;

           

          textinset.TiFile "c:\\B.fm"

           

          Note that the backslash has to be escaped by the backslash to make it work in a JavaScript string. To make your script fail-safe, test the textinset filename before changing it. You may not have the textinset you expect to have, as there may also be text insets on master and reference pages. All text insets are in one single linked list.

           

          Also, updating the text insets after changing the path may not always work, as FM compares the last changed date of the text inset file with the last time the textinset was updated. To force FM to update the textinset, you should include the following code line after changing the text inset file name:

           

          textinset.LastUpdate = 0;

           

          Then you can call the UpdateTextInset() method and it will work.

           

          Good luck.

           

          Jang

          • 2. Re: Changing the text inset's source file with a script
            David A Koot Level 1

            Thank you very much, Jang! That does the job.

             

            (For anyone else who is reading and trying this, Jang's line

             

            textinset.TiFile "c:\\B.fm"

             

            should have been:

             

            textinset.TiFile = "c:\\B.fm"

             

            just a typo in the script...)