Use the dispatcher for other modules than Calc or Writer.

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Sébastien C
Posts: 111
Joined: Mon Jan 04, 2010 5:06 pm
Location: Meymac, France

Use the dispatcher for other modules than Calc or Writer.

Post by Sébastien C »

Hi all !

Because I find this module very easy to use and, once known, very effective, I love working with Draw. In my opinion, this module would be better known, more developed, more worked. But it's already very good! And I also love doing macros with what the API offers us. This is extremely powerful, especially if you have fun drawing things with external data sources such as Calc or even Writer.

However, I was working recently to set up a shape (a textbox with a barcode font) and I wanted to convert it to a polygon, for, in a second time, keep only the bars and delete the numbers. This is possible in Draw by menus (Modify - Convert - To Polygon). But no matter since I looked in the API, both in Bernard Marcelly's text and Andrew Pitonyak's text, I did not find it. In this case, we necessarily turn to the dispatcher. It causes the macro recording, which produces very ugly code, that we arrange a little. And it often works very well.

But, save code with the dispatcher is a luxury that you can afford only with Calc or Writer. The other modules of the suite are excluded.

This is an old French forum thread that is almost ten years old. And I remembered it without the least concern as he impressed me at the time. The solution was found by Alain de la Chaume. It was not a matter of "converting a shape into a polygon", but just showing or hide the page preview pane.

I translate here Alain's explanations:
Alain de La Chaume wrote:I was inspired by a macro recorded with Writer to understand what arguments to pass and how to pass them.

I chose the Show / Hide Navigator action (from the View menu) which returns this code to me:

Code: Select all

sub showHideNavig
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Navigator"
args1(0).Value = false

dispatcher.executeDispatch(document, ".uno:Navigator", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Navigator"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:Navigator", "", 0, args2())
end sub
I just have to find the keyword that should replace Navigator...

To force OpenOffice/LibreOffice to generate a config menu file in my personal environment, I added a menu item in View, of the Draw module of course.

Then I went to consult the config file: menubar.xml
in the root: 'myPersoDirectory'/.config/libreoffice/4/user/config/soffice.cfg/modules/sdraw/menubar/
who told me everything on the subject, by a simple reading of the disposition of lines.

Code: Select all

<menu:menuitem menu:id=".uno:LeftPaneDraw"/>
Uh ... yes, it's true that without digging a little, a lot, even passionately ...
It's not cooked at all!

So; ten years later, this research method is still valid and I was able to convert my textShape into polygons in Draw.

Code: Select all

myText = monDocumentDraw.createInstance("com.sun.star.drawing.TextShape")

' Bla - bla - bla &c.

 ' Conversion into polygons and dissociation of objects with the dispatcher.
myDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
 myDrawDocument.currentController.select(myText)                         ' Visible selection.
 myDispatcher.executeDispatch(myDrawDocument.currentController.Frame, ".uno:ChangePolygon", "", 0, array())
 myDispatcher.executeDispatch(myDrawDocument.currentController.Frame, ".uno:Dismantle"    , "", 0, array())
If we find today without any problem the list of all uno commands, their organization following the menus is much simpler with the method of Alain de la Chaume. So this is a good opportunity to recall it here.

:mrgreen:
LibreOffice v. 7.3.2.2, under GNU-Linux Mint and, in virtualization and just for tests, LibreOffice v. 7.3.2.2 an OpenOffice v. 4.1.12 under M$-W 10 :ouch: .
Post Reply