Quantcast
Channel: Adobe Community: Message List - FrameMaker Scripting
Viewing all articles
Browse latest Browse all 3715

Re: TextLoc works once, then stops working

$
0
0

Hi Mark (and Rick),

 

I want to correct something in your understanding of the TextLoc object.

 

The order of commands does not have anything to do with the problem that the code only ran once after restart and then stopped. The issue is that the TextLoc contains a pointer to the object and an offset, and both must be initialized. If you add one line to the code, as shown below, the script works fine every time.

 

var doc = app.ActiveDoc;

var t1 = new TextLoc();

var firstPgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

t1.obj = firstPgf;

t1.offset = 0;

doc.AddText (t1, "Hello");

 

If you omit setting the offset, it will accidentally have the value 0 when it is first used, but it gets changed to something undefined when adding text - there is no way to tell what FM makes of it. If the value is outside of the range of the object you are pointing to, FM will simply refuse to add the text.

 

The reason why Rick's code worked is that he used another method of creating the TextLoc object, which takes the object and an offset as reference explicitly. That of course works anytime.

 

Kind regards

 

Jang


Viewing all articles
Browse latest Browse all 3715

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>