Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Re: Get text selection and properties

$
0
0

I just want to add for the OP: textStyleRanges will change every time the formatting of texts is changed. In the case of subtle changes at first glance to the text you cannot see them when looking in the UI. It could be anything you could format a text with.

 

So, if you are after some destinct properties (out of maybe 300), you may need other methods to be effective.

 

And another important thing: in the case your paragraphStyle includes GREP Style definitions, the method using textStyleRanges will not work as expected.

 

Example:

 

TextStyleRanges_WithGREPStylesInParaStyle.png

 

If you then ask how many textStyleRanges your selection will consist of,

the result will be: 1

 

Asking for the fillColor of that range you'll get in my example:

 

"C=100 M=0 Y=0 K=0"

 

However, if you ask your selection for the fillColor.name of every individual character with

 

var mySelection = app.selection[0];
var myCharacters = mySelection.texts[0].characters.everyItem().getElements(); for(var n=0;n<myCharacters.length;n++){    $.writeln(myCharacters[n].fillColor.name);    };

 

you'll get the following answer:

 

"C=100 M=0 Y=0 K=0" for character 1 of your selection

"C=0 M=100 Y=0 K=0" for character 2 of your selection

 

Uwe


Viewing all articles
Browse latest Browse all 37788

Trending Articles