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

How to reduce selection by ¶ mark?

Community Expert ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

Dear all,

When a selection contains the ¶ mark, then the TR.end.offset is 0. If i manually reduce the selction to not contain the ¶ mark, then I get a reasonable value (e.g. 279).

How can I programmatically reduce the selection? I have tried the following, but this does not work

#target framemaker
main ();

function main () {
var TR = app.ActiveDoc.TextSelection;
  if (TR.end.offset == 0) {
    $.bp(true); // this provides a huge end.offset, not a reasonable value
    TR.end.obj = TR.beg.obj;
    TR.end.offset = Constants.FV_OBJ_END_OFFSET;
  }
}



TOPICS
Scripting

Views

992

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

Community Expert , Mar 31, 2020 Mar 31, 2020

Hi Klaus, See if this is what you need:

#target framemaker
main ();

function main () {
var TR = app.ActiveDoc.TextSelection;
  if (TR.end.offset == 0) {
    TR.end.obj = TR.beg.obj;
    TR.end.offset = Constants.FV_OBJ_END_OFFSET - 1;
    app.ActiveDoc.TextSelection = TR;
  }
}

Votes

Translate

Translate
Community Expert ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

Hi Klaus, See if this is what you need:

#target framemaker
main ();

function main () {
var TR = app.ActiveDoc.TextSelection;
  if (TR.end.offset == 0) {
    TR.end.obj = TR.beg.obj;
    TR.end.offset = Constants.FV_OBJ_END_OFFSET - 1;
    app.ActiveDoc.TextSelection = TR;
  }
}

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
Community Expert ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

Rick, thousand thanks!

Its interaesting: if I right from the beginning select without the ¶ mark, then TR.end.offset is (in this test) 398. With the method You provide the value is 1342177279 - probably from the beginning of the document. Nevertheless the new selection is correct and the rest of the script works as expected.

 

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
Community Expert ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

LATEST

Hi Klaus,

 

The Constants.FV_OBJ_END_OFFSET is an extremely high number that is always the same value, regardless of where you are in the document. When using this for a text range, it always denotes the end of the range; in the case of a paragraph, it includes the end-of-paragraph symbol. It is provided as a shorthand in order to be able to make a text range of an entire text object without knowing its actual end offset. As you can see, you can use math to change the offset as needed. In your case, we subtracted 1 from the value in order to leave the end of the paragraph out of the text range.

 

I think there is at least one example of this in the FDK documentation.

 

-Rick

 

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