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

Javascript | How to change the displayed selection in the textFrame using a script?

Explorer ,
Oct 01, 2020 Oct 01, 2020

Hi everyone,

 

I was wondering if it is possible via javascript to change the highlighted selection via javascript?

here's an example, we can imagine this layout, which has a selection (some parts of second paragraph):

Capture d’écran 2020-10-01 à 15.40.52.png

 

Is it possible via a javascript to change the displayed selection with the first paragraph instead without using the mouse, like this:

Capture d’écran 2020-10-01 à 15.41.00.png

I didn't find anything working for now…

thanks everyone 🙂

Nicolas

TOPICS
Scripting
835
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

Explorer , Oct 01, 2020 Oct 01, 2020

Nevermind, I found the solution, here it is if it could help someone else:

[your item].showText()

 

Have a nice day 🙂

Nicolas

Translate
Explorer ,
Oct 01, 2020 Oct 01, 2020

Nevermind, I found the solution, here it is if it could help someone else:

[your item].showText()

 

Have a nice day 🙂

Nicolas

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 ,
Oct 01, 2020 Oct 01, 2020

Hi Nicolas,

your code cannot work.

What exactly should [your item] stand for?

 

To make that work you first have to calculate what exactly is selected.

You also want to know what the parent of the selection is.

 

Regards,
Uwe Laubender

( ACP )

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
Explorer ,
Oct 01, 2020 Oct 01, 2020

Hey Uwe!

 

I should have writtent a more specific example:

app.selection[0].paragraphs[-1].insertionPoints[-1].paragraphs[-1].showText()

1. In the example below, you have to select a paragraph.

2. Run the script

3. The displayed selection (in indesign not in javascript) will be the next paragraph just after your selection.

 

All the best,

Nicolas

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 ,
Oct 01, 2020 Oct 01, 2020

There’s also select()

 

app.selection[0].paragraphs[-1].insertionPoints[-1].paragraphs[-1].select();

 

 

The difference between the showText() and selection() might matter. The showText() method can change the active page as well as make the selection. If your text selection is on page 1, and your activePage is page 10, showText() will make the selection and change your activePage view to page 1—select() will only make the selection. 

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
Explorer ,
Oct 02, 2020 Oct 02, 2020

Hello Rob!

 

Thanks for the precision, that will be usefull aswell.

 

Nicolas

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 ,
Oct 01, 2020 Oct 01, 2020

Hi Nicolas,

thank you for your explanation.

Now your posted code is working as expected when I look at your screenshot.

 

But also test your script on selected text that covers parts of the last paragraph of a story.

Test two cases:

[1] A paragraph character is applied as the last character in the story.

[2] No paragraph character is applied as the last character in the story.

 

Regards,
Uwe Laubender

( ACP )

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
Explorer ,
Oct 02, 2020 Oct 02, 2020

Hello Uwe,

 

Did you mean to test before if the next paragraph exists before triying to show it?

 

Cheers,

Nicolas

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 ,
Oct 02, 2020 Oct 02, 2020
LATEST

🙂

First test the two cases and then draw conclusions.

 

Best,
Uwe Laubender

( ACP )

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