Draw: How to Merge/Subtract/Intersect shapes via macro?

For example I want to do it for 2 rectangles as from menu Shape ->
Merge/Subtract/Intersect

Macro twoRectangles put 2 rectangles to the Draw page and select them.

Sub twoRectangles 'put 2 rectangles to the Draw page and select them
  dim oDrawDoc,oPage,oRect1,oRect2,oShapes,oSelect
  oDrawDoc=thisComponent
  oPage=oDrawDoc.getDrawPages().getByIndex(0)

  rem put rectangle 1
  oRect1=oDrawDoc.createInstance("com.sun.star.drawing.RectangleShape")
  oRect1.setPosition(createPoint(1000, 1000))
  oRect1.setSize(createSize(4000, 3000))
  oPage.add(oRect1)

  rem put rectangle2
  oRect2=oDrawDoc.createInstance("com.sun.star.drawing.RectangleShape")
  oRect2.setPosition(createPoint(2000, 1500))
  oRect2.setSize(createSize(5000, 2000))
  oRect2.fillColor=RGB(123,34,78) 'other color
  oPage.add(oRect2)

  rem shapes to collection
  oShapes=createUnoService("com.sun.star.drawing.ShapeCollection")
  oShapes.add(oRect1)
  oShapes.add(oRect2)

  rem shapes to selection
  oDrawDoc.CurrentController.Select(oShapes)
  oSelect=oDrawDoc.getCurrentController().getSelection()

  rem now I can do manually: menu Shape -> Merge/Subtract/Intersect, but how
via macro???
End Sub

Function CreatePoint(ByVal x As Long,ByVal y As Long) As
com.sun.star.awt.Point
  Dim oPoint
  oPoint=createUnoStruct( "com.sun.star.awt.Point" )
  oPoint.X=x : oPoint.Y=y
  CreatePoint=oPoint
End Function

Function CreateSize(ByVal x As Long,ByVal y As Long) As
com.sun.star.awt.Size
  Dim oSize
  oSize=createUnoStruct( "com.sun.star.awt.Size" )
  oSize.Width=x : oSize.Height=y
  CreateSize=oSize
End Function

Hi Kamil,

For example I want to do it for 2 rectangles as from menu Shape ->
Merge/Subtract/Intersect

You can use the dispatcher for it. After the shapes are selected do
for example:
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:Merge", "", 0, Array())

Of cause you need to adapt the identifiers and omit already done declarations.

Array() means, that this uno-command needs no arguments.

The SID in core is SID_POLY_MERGE. Looking in https://opengrok.libreoffice.org/xref/core/svx/sdi/svx.sdi#5675
you see, that the argument brackets () are empty.

The others are accordingly .uno:Subtract and .uno:Intersect

Kind regards
Regina

Thank you very much, it behaves OK.

Only for Subtract must be .uno:Substract

but I can tell you what has happened to libre office over the past two years has turned me off..
nothing about it is stable.. it stinks.

Everyone apart from you is out of step??

User since LibreOffoce started, and before years of OpenOffice..
Never had stability problems whatsoever, but the latest release 6.1.4 made me wonder.

I went back from 6.1.4 to 6.0.7 because 6.1.4 made a mess of the screen anytime I scrolled fast (in calc), or, especially in the function wizard (which was really unusable).

No problems whatsoever in 6.0.7, though.

Environment MacBook Pro, MacOS Mojave 10.14.2

I use Libre everyday. Never had a stability issue. My spreadsheets are up and
used seven days a week around 60 tabs and under 900 rows per tab. No issues.

I would say its user and/or user machine issues.

The original message is classic trolling, but Rob, have you asked here
or checked bug reports or filed them if not present? Like others I have
been using LO (fresh) on Linux for a few years now without any
stability issues. There is one bug report I filed recently over a GTK3
UI issue that seems to have been fixed. So, yes, we can always roll
back to a version that worked well for us, but we can also raise issues
here and file bug reports so that the software can continue developing
and bugs are not left to fester. The developers are very responsive,
just one more plus for LO.

At the moment it happened I did install the new LO over the old one (since I never had any serious problems :grinning:), so I reversed the same way. At that moment in time I didn’t have the time to work it.
I will however re-install 6.1.4 side-by-side to see if it tase the same behavior as before. If so, I’ll certainly report it.

I started using StarOffice a ways back, then OpenOffice.org, then Libreoffice since Oracle bought Sun.
I do not now have, nor have I ever had, stability problems, except _sometimes_ when I install a new release over the old one.  Now, I _always_ remove the old version before installing a new version. Never a problem since.

I note that I need to install a new version.

-- David

Version: 6.2.1.2 (x64)
Build ID: 7bcb35dc3024a62dea0caee87020152d1ee96e71
CPU threads: 4; OS: Windows 6.1; UI render: default; VCL: win;
Locale: en-US (en_US); UI-Language: en-US
Calc: threaded