[Solved] Insert Annotation/Coment in Writer from macro

Creating a macro - Writing a Script - Using the API

[Solved] Insert Annotation/Coment in Writer from macro

Postby Trainux » Tue Jan 14, 2014 5:21 pm

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   Expand viewCollapse view
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
Trainux
 
Posts: 19
Joined: Fri Jan 03, 2014 10:39 am

Re: Insert Annotation/Coment in writer from macro

Postby FJCC » Tue Jan 14, 2014 5:54 pm

I suggest something like this instead, which inserts a comment at the position of the view cursor
Code: Select all   Expand viewCollapse view
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)
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7751
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Insert Annotation/Coment in writer from macro

Postby RoryOF » Tue Jan 14, 2014 6:53 pm

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

http://en.ooo-info.org/documentation/annotation_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.developpez.com/faq/?page=Les-annotations 
Apache OpenOffice 4.1.7 on Xubuntu 20.04.1 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 31446
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Insert Annotation/Coment in writer from macro

Postby Trainux » Tue Jan 14, 2014 6:54 pm

FJCC wrote:I suggest something like this instead, which inserts a comment at the position of the view cursor
Code: Select all   Expand viewCollapse view
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
Trainux
 
Posts: 19
Joined: Fri Jan 03, 2014 10:39 am


Return to Macros and UNO API

Who is online

Users browsing this forum: Google [Bot] and 6 guests