Skip navigation
David A Koot
Currently Being Moderated

Changing the text inset's source file with a script

Jul 2, 2013 4:56 AM

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

 
Replies
  • Currently Being Moderated
    Jul 2, 2013 5:21 AM   in reply to David A Koot

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points