Macros/Impress/002

    From The Document Foundation Wiki


    Other languages:

    Description

    It is often useful to be able to selectively loop through a specific class of objects in the current slide. For example you may have various objects in the slide, like images ie com.sun.star.GraphicObjectShape or shapes such as com.sun.star.drawing.RectangleShape. But say you want to change a property for all of a specific shape?

    The macro below loops through all com.sun.star.drawing.LineShape[1] objects, and then changes some properties for each LineShape. Hence the macro illustrates the various relevant properties that you may want to address for LineShape objects, such as color, and it also illustrates how to selectively loop through objects in the current slide.

    Needless to say the macro hence provides a template for other applications as well. A modified version of the below code, is included for download in the ODP file below, where the macro has been separated into multiple macros and assigned to different Push Buttons, as shown in this screenshot:

    Slide with Push Buttons linked to macros which loop through and alter LineShape properties.




















    Code

    LibreOffice Basic

    'Option Explicit
    
    Sub manipulate_lineshapes ()
        '''Selectively loop through all com.sun.star.drawing.LineShape objects and manipulate their properties.'''
    
        oSlide = ThisComponent.CurrentController.CurrentPage
    
        For i = 0 To oSlide.getCount()-1
            With oSlide.getByIndex(i)
                If .getShapeType() = "com.sun.star.drawing.LineShape" Then
    
                    .LineWidth = .LineWidth + 50
                    .LineEndWidth = .LineEndWidth + 50
                    .LineEndName = "Square"  ' Arrow, Square, Circle, etc
                    .LineColor = RGB(52,101,164)
                    .LineStyle = com.sun.star.drawing.LineStyle.DASH   ' .SOLID or .DASH or .NONE
                    .LineDashName = "Ultrafine Dashed" ' Fine Dashed, Fine Dotted, Ultrafine Dashed, etc
    
                End If
            End With
        Next
    
    End Sub ' manipulate_lineshapes

    Python

    tbc

    Download ODP file

    Notes