Manipulate LineShape objects selectively in current slide

    From The Document Foundation Wiki

    Other languages:


    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 or shapes such as But say you want to change a property for all of a specific shape?

    The macro below loops through all[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.


    LibreOffice Basic

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



    Download ODP file