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

How to remember the position of a TextLoc at the end of a paragraph

Community Expert ,
Feb 05, 2025 Feb 05, 2025

Hi,

I have a TextLoc problem. Sorry, when this is to basic for some of you.

I have a paragraph with text.

My script does this:

1 Applies a condition to this text.

2 Adds new text after this text.

3 Then applies another condition to the new text.

I do not know, how I can remember the offset of the TextLoc at the end of the text after step 1.

I use Constants.FV_OBJ_END_OFFSET-1 for this TextLoc.

However, when I add the text, the offset is still at the end of the paragraph and not at the end of the first text.

When I store the offset in another variable, it's always at the end of this paragraph.

Is there another way to to count the offset?

Or do I have to use TextItems with GetText and somehow calculate the single text items?

This snippet illustrates what I mean. "789" should be inserted after "123". However, it is added at the end of the paragraph.

#target framemaker
"use strict";
#strict on

var loDoc, loPgf, loTLoc, loTLocStartOffset;

loDoc = app.ActiveDoc;
if (!loDoc.ObjectValid ()) {
    Alert ("Document required ", Constants.FF_ALERT_CONTINUE_NOTE);
}
loFlow = loDoc.MainFlowInDoc;
loPgf = loFlow.FirstTextFrameInFlow.FirstPgf;
loTLoc = new TextLoc ();
loTLoc.obj = loPgf;
loTLoc.offset = 0;
loDoc.AddText (loTLoc, "123");
loTLoc.offset = Constants.FV_OBJ_END_OFFSET-1;
loTLocStartOffset = loTLoc.offset;
$.writeln ("loTLocStart.offset: " + loTLocStart.offset);
loDoc.AddText (loTLoc, "456");
loTLoc.offset = loTLocStartOffset;
loDoc.AddText (loTLocStart, "789");

Thank you very much for your help!

Best regards, Winfried

263
Translate
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

Enthusiast , Feb 05, 2025 Feb 05, 2025

Hi Winfried,

try this:

 


loFlow = loDoc.MainFlowInDoc;

loPgf = loFlow.FirstTextFrameInFlow.FirstPgf;

loTLoc = new TextLoc ();

loTLoc.obj = loPgf;

loTLoc.offset = 0;

loDoc.AddText (loTLoc, "123");

loTLoc.offset = loTLoc.offset + "123".length

loTLocStartOffset = loTLoc.offset;

loDoc.AddText (loTLoc, "456");

loTLoc.offset += "456".length;

loDoc.AddText (loTLoc, "789");

 

You don't have to look for EndOfOffset

Just "count"

Translate
Enthusiast ,
Feb 05, 2025 Feb 05, 2025

Hi Winfried,

try this:

 


loFlow = loDoc.MainFlowInDoc;

loPgf = loFlow.FirstTextFrameInFlow.FirstPgf;

loTLoc = new TextLoc ();

loTLoc.obj = loPgf;

loTLoc.offset = 0;

loDoc.AddText (loTLoc, "123");

loTLoc.offset = loTLoc.offset + "123".length

loTLocStartOffset = loTLoc.offset;

loDoc.AddText (loTLoc, "456");

loTLoc.offset += "456".length;

loDoc.AddText (loTLoc, "789");

 

You don't have to look for EndOfOffset

Just "count"

Translate
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
Community Expert ,
Feb 05, 2025 Feb 05, 2025

Thank you very much!

This will work, as I will not have any character formats applied in the text or any other non-string text item.

However, is there also a general solution, when something like this would be in there? Would I have to count all text items and add the number of characters in all strings?

Translate
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
Community Expert ,
Feb 05, 2025 Feb 05, 2025
LATEST

Something so that ExtendScript automatically shows the number of text items (characters and all other text changes) from the beginning to this TextLoc?

Translate
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