Re: Script issue on getting text


Noelia Ruiz
 

Hello: One of the possibilities maybe:

try:
                                T = FO.makeTextInfo(textInfos.POSITION_CARET)
                                T.expand(textInfos.UNIT_WORD)
                                The Word = T.text

except Exception as e (or probably better Except NotImplementedError):
ui.message"No word at caret position").

Hope this helps.


2021-02-21 17:02 GMT+01:00, שמואל רטבי <shretbi@gmail.com>:

Hello all

Thank you to allwhose help was very useful so far.

In the following lines of script, I try to get text at the caret position :

FO = api.getFocusObject()

T =
FO.makeTextInfo(textInfos.POSITION_CARET)

T.expand(textInfos.UNIT_WORD)

The Word = T.text



If the caret happens not to be at some character position, the expression

T.text

Causes an error (something like :

Invalid NVDAObject start point. or so

What is the simplest way to catch the error before it occurs and have
TheWord = "Nothing at cursor position"

Note : I tried "Try" but I don't get out of it without some bones broken.

Thanks in advance

Shmuel








Join nvda-addons@nvda-addons.groups.io to automatically receive all group messages.