How do I select text in a text frame with a macro?

asked 2020-02-20 02:44:29 +0200

lomacar gravatar image

updated 2020-07-27 15:31:29 +0200

Alex Kemp gravatar image

I know I can get a view cursor for the document with

viewCursor = ThisComponent.CurrentController.getViewCursor

And I can get a text cursor in a frame with

oFrame = ThisComponent.createInstance( "com.sun.star.text.TextFrame" )
frameCursor = oFrame.getText().createTextCursor()

But I don't know how to set the view cursor to the range of the text cursor. If I try to do

viewCursor.gotoRange(frameCursor, true)

it gives an error with no message. I assume it is a conflict because the view cursor is outside the frame and I'm trying to set it to a range inside the frame. I think I need to create a different view cursor inside the frame somehow?

Ultimately I want to be able to search for all-caps words inside the frame and set them to small caps. I don't think this can be done directly with LO Basic, so I figured I would just select the frame text and then run a macro which is a recording of a regex search followed by

dispatcher.executeDispatch(document, ".uno:SmallCaps", "", 0, Array())

But if there is a better way to do this whole thing, then that is great too.

edit retag flag offensive close merge delete