Macros/Impress/001

From The Document Foundation Wiki
Jump to: navigation, search

Template:TopMenu/en Template:Menu/en Template:Menu.Macros/en

Other languages:

Description

This macro will insert a com.sun.star.drawing.RectangleShape[1] to the currently selected slide in an Impress document, with various custom presets as specified in the code.

Code

In LibreOffice Basic:

Option Explicit

Sub InsertRectangleShape()
    '''Insert a RectangleShape to the currently selected slide'''

    Dim oDoc As Object ' com.sun.star.lang.XComponent
    Dim oSlide As Object ' com.sun.star.drawing.XDrawPage
    Dim oRectangle As Object ' com.sun.star.drawing.RectangleShape
    Dim oSize As New com.sun.star.awt.Size
    Dim oPosition As New com.sun.star.awt.Point

    oDoc = ThisComponent
    oSlide = oDoc.CurrentController.CurrentPage
    oRectangle = oDoc.createInstance("com.sun.star.drawing.RectangleShape")

    With oSlide
        .add(oRectangle)
        oPosition.X = .7*(.Width - oSize.Width)
        oPosition.Y = .7*(.Height - oSize.Height)
    End With ' oSlide

    oSize.Width = 5000
    oSize.Height = 3000
    With oRectangle
        .setSize(oSize)
        .setPosition(oPosition)
        .FillColor = RGB(0,0,255)
        .FillStyle = com.sun.star.drawing.FillStyle.SOLID ' or .NONE
        .FillTransparence = 30

        .LineStyle = com.sun.star.drawing.LineStyle.SOLID ' or .NONE
        .LineWidth = 100
        .LineColor = RGB(0,0,0)

        .setName("MyRectangleName")
        .setString("Hello!")
        .charFontName = "Liberation Sans"
        .charColor = RGB(255,255,255)
        .ZOrder = 1
    End With ' oRectangle

End Sub ' InsertRectangleShape

ODP file to test macro

Notes