• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Changing the text inset's source file with a script

New Here ,
Jul 02, 2013 Jul 02, 2013

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

617

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jul 02, 2013 Jul 02, 2013

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 text

...

Votes

Translate

Translate
Advocate ,
Jul 02, 2013 Jul 02, 2013

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 02, 2013 Jul 02, 2013

Copy link to clipboard

Copied

LATEST

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...)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines