Object Placement at cursor position

Following up from my last post, I am trying to write a macro that will allow me to place a small circle at my cursor position for editing scripts for Broadway style musicals.

I borrowed a bit of code from this post on stackoverflow:(https://stackoverflow.com/questions/44368014/how-to-get-document-coordinates-from-a-mouse-click-in-an-openoffice-basic-macro)

The poster mentions that not everyone will have the same accessible content, which I believe is why it is failing inside of my macro. Can anyone explain why that is? In addition, I’ve had issues previously trying to use the “getText” call inside of Impress (editing), is this normal?

Sub InsertProcessShape 
 Dim oDoc As Object
 Dim oDrawPage As Object
 Dim oShape As Object
 Dim shapeGeometry(0) as new com.sun.star.beans.PropertyValue
 Dim oSize As new com.sun.star.awt.Size

 oSize.width = 1200
 oSize.height = 1200

 oDoc = Stardesktop.getCurrentComponent()
 oCurrentController = oDoc.getCurrentController()
 oDrawPage = oCurrentController.CurrentPage

 oShape = oDoc.createInstance("com.sun.star.drawing.EllipseShape")
 shapeGeometry(0).Name = "Type"
 shapeGeometry(0).Value = "Circle"
 oDrawPage.add(oShape)
 oShape.Size = oSize
 oShape.FillStyle = com.sun.star.drawing.FillStyle.NONE
 oShape.LineWidth = 170
 oShape.LineColor = 220

 Dim aPosition As New com.sun.star.awt.Point
 Dim o1, o2, o3, o4, o5, o6

 REM // First get AccessibleContext of the Window of the active Frame of the Application
 o1 = StarDesktop.ActiveFrame.ContainerWindow.AccessibleContext

 REM // 7th AC of o1 is the StatusBar at the bottom;
 o2 = o1.GetAccessibleChild(6).AccessibleContext

 REM // 2nd AC of o2 is the Position + Size of the Selection (e.g: "10,95 / 14,980,00 x 0,00") 
 o3 = o2.GetAccessibleChild(1)
 o4 = o3.GetText()

 REM // Taking out only the coordinates from o4
 REM // TODO: Check for negatives (longer)
 o5 = LEFT(o4, 4)
 o6 = MID(o4, 8, 5)

 aPosition.X = o5
 aPosition.Y = o6

 oShape.setposition(aPosition)

 oShape.Text.String = "1"
 oShape.Text.CharHeight = 20
 oShape.Text.CharFontName = "Alef"

End Sub

Hello,

The method you chose is not going to work. Post is over two years old and seems to relate to Open Office. LO may have differences. Data used is from the status bar and it returns spaces in LO. See no immediate method using the status bar info.

Probably best to use a mouse handler. Testing one with your code (removed non working code) but have not found how to accurately get the mouse co-ordinates. Come fairly close often but other times not close enough. Also still having problems with macros wiping out editing possibilities. Makes testing most difficult. May try to switch to different LO version for this tomorrow.

Edit 2019-08-30:

Unfortunately testing has become unlivable with Impress for me. Even changing macros & closing the file will cause loss of Slide editing. Tried other LO versions and had similar problems. Other LO modules do not have this problem for me.

As stated, using a mouse handler seemed to be the direction with results. Best to you.