The main problem here is that I can't move my ViewCursor the the text shape. Here's what my code looks like and what I've tried:
Code: Select all
# variables is a string that looks like this: "$variable"
# doc is my current text document
# cursor is the ViewCursor of this document
for page in doc.getDrawPages():
for shape in page:
if shape.getShapeType() == "com.sun.star.drawing.TextShape":
while (index_occurrence := shape.String.find(variable)) != -1:
cursor.gotoRange(shape, False)
cursor.goRight(index_occurrence, False)
cursor.goRight(len(variable), True)
self.cnx.dispatcher.executeDispatch(
doc.CurrentController.Frame,
".uno:Paste", "", 0, ())
Code: Select all
File "test.py", line 364, in text_fill
cursor.gotoRange(shape, False)
uno.com.sun.star.uno.RuntimeException: at ./sw/source/uibase/uno/unotxvw.cxx:1040
Code: Select all
# variables is a string that looks like this: "$variable"
# doc is my current text document
# cursor is the ViewCursor of this document
for page in doc.getDrawPages():
for shape in page:
if shape.getShapeType() == "com.sun.star.drawing.TextShape":
shape_cursor = shape.createTextCursor()
shape_cursor.collapseToStart()
while (index_occurrence := shape.String.find(variable)) != -1:
cursor.gotoRange(shape_cursor, False)
cursor.goRight(index_occurrence, False)
cursor.goRight(len(variable), True)
self.cnx.dispatcher.executeDispatch(
doc.CurrentController.Frame,
".uno:Paste", "", 0, ())
Code: Select all
File "test.py", line 363, in text_fill
cursor.gotoRange(shape_cursor, False)
uno.com.sun.star.uno.RuntimeException: at ./sw/source/uibase/uno/unotxvw.cxx:1040