Replace Annotation/Comment Anchor Content while keeping the Annotation

I’d like to be able to replace the content of a Writer Annotation/Comment anchor. From my experiments doing the following does replace the anchor content, but also destroys the annotation, which I would like to keep intact.

oCurs = annotation.Anchor
oText = oCurs.getText()
oText.insertTextContent(oCurs, newContent, True)

Is there any way to do this?

Hello!
I think the standard approach is to create a new annotation, transfer the old annotation’s information into it, and then delete the old annotation. Or is something else meant?

Yeah, I know it’s possible to do it that way, but there are unfortuantely some issues that I’ve noticed with it. For example, it seems to me that the changes to the annotation content are not immediately visible in the document from the macro, but rather become visible when user leaves the annotation edit box - that means that deleting the annotation clears any changes that may have happened to the annotation as far as the user is concerned. I’ve also been having issues with the new annotations sometimes not being created when processing multiple of them, and my assumption was that not deleting them in the first place would probably help to mitigate that. The third issue is the metadata (creation date, author, etc.) - I presume there most likely is some way to set those when creating a new annotation in order to match the old one, but it would also mean that I would have to update the code every time a new metadata field is added to LibreOffice, and I don’t think I should be expected to bear that responsibility.

I’m sure what you want can be done with a macro but
Manipulating comments (anchor, content, or date) distorts the work of the person who wrote the comment, to put it another way, it is identity theft.

I think @sokol92 's approach is the most reasonable.

I guess that is sort of true, maybe I’m still asking the wrong questions. Does Writer have any good alternatives to comments when I’d like to store source code for content to be generated by a macro, such as a PlantUml diagram? The comments seem like a great fit to me, because the source code is not visible in the output pdf, the source code is not out of the way when editing, and there is no doubt about where the output should be placed.

I think that for block diagrams the best option is to work in Draw
with the possibility of exporting images and transferring them to Writer.

  • I don’t understand the need for macros.

Simply writing the PlantUML code and having it insert the image for you is much faster when you’re working with a large number of diagrams. Maybe it doesn’t sound like much, but it adds up quickly.