Création d'un rectangle

Bonjour.
Je cherche à générer un rectangle avec une macro, que j’ai mise sur un bouton dans Impress.
Pour l’instant, ça crée un minuscule carré en (0,0) dans la diapositive 0. Les attributs Position, Size et BoundRect semblent sans effet.
Voici le code :


Sub InsererRectangleBlancSansBordure()

    Dim oDoc As Object
    Dim oDrawPageSupplier As Object
    Dim oDrawPage As Object
    Dim oShape As Object

    oDoc = ThisComponent

    ' Interface correcte pour accéder au DrawPage
    oDrawPageSupplier = oDoc

    oDrawPage = ThisComponent.getDrawPages().getByIndex(0)

    ' Création du rectangle
    oShape = oDoc.createInstance("com.sun.star.drawing.RectangleShape")

    ' Ajout
    oDrawPage.add(oShape)
    
    ' Position / taille
    oShape.BoundRect.X = 2000
    oShape.BoundRect.Y = 2000
    oShape.BoundRect.Width = 6000
    oShape.BoundRect.Height = 3000

    ' Remplissage blanc
    oShape.FillColor = RGB(255, 0, 0)

    ' Pas de bordure
    oShape.LineStyle = com.sun.star.drawing.LineStyle.NONE

End Sub

Je voudrais réussir à :

  • avoir un rectangle assez grand pour que je le voie (il devra être blanc, à terme, mais il reste en rouge pour l’instant : on le voit mieux)
  • le générer dans la diapo où je me trouve, et non la première
    C’est faisable ?

bonjour
une proposition

sub InsererRectangleBlancSansBordure()
Dim Doc As Object
Dim Page As Object
Dim RectangleShape As Object
Dim Point As New com.sun.star.awt.Point
Dim Size As New com.sun.star.awt.Size

Doc = ThisComponent
rem page 0 Page = Doc.DrawPages(0)
rem page active ' Récupérer la page (diapositive) active
    Page = Doc.CurrentController.CurrentPage rem page active
print "macro 3"
Point.x = 1000
Point.y = 1000
Size.Width = 10000
Size.Height = 10000

RectangleShape = Doc.createInstance("com.sun.star.drawing.RectangleShape")
RectangleShape.Size = Size
RectangleShape.Position = Point

' Remplissage blanc
    oShape.FillColor = RGB(255, 0, 0)

    ' Pas de bordure
    oShape.LineStyle = com.sun.star.drawing.LineStyle.NONE
Page.add(RectangleShape)
end sub

macrorectangle.odp (16.2 KB)

J’ai remplacé oShape par RectangleShape, et ça marche du feu de Dieu. Merci !!!