[Solved] Insert Annotation/Coment in Writer from macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Trainux
Posts: 19
Joined: Fri Jan 03, 2014 10:39 am

[Solved] Insert Annotation/Coment in Writer from macro

Post by Trainux »

Hello, i'm trying simulate the ctrl+Alt+C from macro.
This is my code but the annotation appears empty... What i'm making wrong?

Code: Select all

Sub tp_insertarComentario(ByVal cad As String)
	Dim document   as object
	Dim dispatcher as object
	Dim oct1
	
	
	document = ThisComponent.CurrentController.Frame
	dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	oct1 = ThisComponent.getCurrentController()
	
	
	dim args2(2) as new com.sun.star.beans.PropertyValue
	args2(0).Name = "Text"
	args2(0).Value =  "Text of the annotation" 
	args2(1).Name = "Author"
	args2(1).Value = "Test"
	args2(2).Name = "Date"
	args2(2).Value = ""
	dispatcher.executeDispatch(document, ".uno:InsertAnnotation", "", 0, args2())

End Sub
Last edited by Trainux on Tue Jan 14, 2014 6:55 pm, edited 1 time in total.
Open Office 4.0.1 in Windows 7
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Insert Annotation/Coment in writer from macro

Post by FJCC »

I suggest something like this instead, which inserts a comment at the position of the view cursor

Code: Select all

oAnno = ThisComponent.createInstance("com.sun.star.text.textfield.Annotation")
oAnno.Content = "My Text"
oAnno.Author = "f c"
oText = ThisComponent.Text
oVC = ThisComponent.CurrentController.ViewCursor
oText.insertTextContent(oVC.Start, oAnno, False)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
RoryOF
Moderator
Posts: 34617
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Insert Annotation/Coment in writer from macro

Post by RoryOF »

If you download Annotation Tool and inspect its code I think you should get what you need,

http://en.ooo-info.org/documentation/an ... _tool.html project was called AnnotationTool

 Edit: Above link is dead - site abandoned (08 February 2018).

This link may provide some assistance
https://openoffice-libreoffice.developp ... nnotations 
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
Trainux
Posts: 19
Joined: Fri Jan 03, 2014 10:39 am

Re: Insert Annotation/Coment in writer from macro

Post by Trainux »

FJCC wrote:I suggest something like this instead, which inserts a comment at the position of the view cursor

Code: Select all

oAnno = ThisComponent.createInstance("com.sun.star.text.textfield.Annotation")
oAnno.Content = "My Text"
oAnno.Author = "f c"
oText = ThisComponent.Text
oVC = ThisComponent.CurrentController.ViewCursor
oText.insertTextContent(oVC.Start, oAnno, False)
Thanks, work perfectly!
Open Office 4.0.1 in Windows 7
Post Reply