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