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

Explorer ,
Oct 01, 2020

Copy link to clipboard

Copied

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

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

[your item].showText()

 

Have a nice day 🙂

Nicolas

TOPICS
Scripting

Views

139

Likes

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

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

Explorer ,
Oct 01, 2020

Copy link to clipboard

Copied

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

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

[your item].showText()

 

Have a nice day 🙂

Nicolas

TOPICS
Scripting

Views

140

Likes

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

Copy link to clipboard

Copied

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

[your item].showText()

 

Have a nice day 🙂

Nicolas

Likes

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
Reply
Loading...
Oct 01, 2020 0
Adobe Community Professional ,
Oct 01, 2020

Copy link to clipboard

Copied

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 )

Likes

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
Reply
Loading...
Oct 01, 2020 0
Explorer ,
Oct 01, 2020

Copy link to clipboard

Copied

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

Likes

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
Reply
Loading...
Oct 01, 2020 0
Adobe Community Professional ,
Oct 01, 2020

Copy link to clipboard

Copied

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. 

Likes

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
Reply
Loading...
Oct 01, 2020 1
Explorer ,
Oct 02, 2020

Copy link to clipboard

Copied

Hello Rob!

 

Thanks for the precision, that will be usefull aswell.

 

Nicolas

Likes

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
Reply
Loading...
Oct 02, 2020 0
Adobe Community Professional ,
Oct 01, 2020

Copy link to clipboard

Copied

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 )

Likes

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
Reply
Loading...
Oct 01, 2020 0
Explorer ,
Oct 02, 2020

Copy link to clipboard

Copied

Hello Uwe,

 

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

 

Cheers,

Nicolas

Likes

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
Reply
Loading...
Oct 02, 2020 0
Adobe Community Professional ,
Oct 02, 2020

Copy link to clipboard

Copied

🙂

First test the two cases and then draw conclusions.

 

Best,
Uwe Laubender

( ACP )

Likes

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
Reply
Loading...
Oct 02, 2020 0