无法在 LibreOffice Impress 演示模式下使用宏更改形状颜色

问题描述 投票:0回答:1

我正在尝试使用基本宏来使形状在演示模式下单击时改变其颜色。我的目标是创建适用于任何幻灯片的多功能代码,无论形状数量如何。

当我使用“执行交互...”选项时,我有一个可以运行的代码(见下文)。但是,在演示模式下,可以单击形状,但不会更改颜色。我发现演示模式需要特定的编码才能正常工作。不幸的是,我没有成功地让它发挥作用。

与“执行交互...”一起使用的代码:

Sub ChangeColorToGreen_old()
    Dim oDoc As Object
    Dim Page As Object
    Dim oSelection As Object
    Dim SelectedShape As Object

    oDoc = ThisComponent
    Page = oDoc.DrawPages(0)
    oSelection = oDoc.getCurrentSelection()

    If oSelection.getCount() > 0 Then
        SelectedShape = oSelection.getByIndex(0)
    
        If SelectedShape.SupportsService("com.sun.star.drawing.Shape") Then
            If SelectedShape.FillColor = RGB(0, 200, 0) Then
                SelectedShape.FillColor = -1 ' Cor padrão, por exemplo, RGB(255, 255, 255) para branco
            Else
                SelectedShape.FillColor = RGB(0, 200, 0) ' Cor desejada, por exemplo, verde (0, 200, 0)
            End If
        End If
    End If
End Sub

我尝试使用 ChatGPT 和 Bard 来协助我完成此操作,但他们的代码导致了错误消息(见下文)。

ChatGPT 代码是:

Sub ChangeColorToRed_chatgpt()
    Dim oDoc As Object
    Dim oPresentation As Object
    Dim oSelection As Object
    Dim oDrawPage As Object
    Dim oShape As Object

    oDoc = ThisComponent
    oPresentation = oDoc.getPresentation()
    oSelection = oDoc.getCurrentController().getSelection()

    If oSelection.getCount() > 0 Then
        oDrawPage = oPresentation.getDrawPage()
        oShape = oSelection.getByIndex(0)
    
        If oShape.SupportsService("com.sun.star.drawing.Shape") Then
            If oShape.FillColor = RGB(0, 200, 0) Then
                oShape.FillColor = -1 ' Default color, e.g., RGB(255, 255, 255) for white
            Else
                oShape.FillColor = RGB(255, 0, 0) ' Desired color, e.g., red (255, 0, 0)
            End If
        End If
    End If
End Sub

错误是:

Basic runtime error. Property or method not found: GetDrawPage

巴德代码是:

Sub ChangeColorToRedbard()
    Dim oDoc As Object
    Dim oPage As Object
    Dim oController As Object
    Dim oSelection As Object
    Dim SelectedShape As Object

    oDoc = ThisComponent
    oController = oDoc.CurrentController

    If oController.IsInPresentationMode Then
        oController.ExitPresentation
    End If

    oPage = oDoc.DrawPages(0)
    oSelection = oDoc.getCurrentSelection

    If oSelection.getCount() > 0 Then
        SelectedShape = oSelection.getByIndex(0)

        If SelectedShape.SupportsService("com.sun.star.drawing.Shape") Then
            If SelectedShape.FillColor = RGB(0, 200, 0) Then
                SelectedShape.FillColor = -1 ' Cor padrão, por exemplo, RGB(255, 255, 255)     para branco
            Else
                SelectedShape.FillColor = RGB(0, 200, 0) ' Cor desejada, por exemplo, verde     (0, 200, 0)
            End If
        End If
    End If

    If oController.IsInPresentationMode Then
        oController.EnterPresentation
    End If
End Sub

错误是:

Basic runtime error. Property or method not found: IsInPresentationMode

我正在使用 LibreOffice 7.6.4.1 60 和 Manjaro。

DISTRIB_ID="ManjaroLinux"
DISTRIB_RELEASE="23.1.3"
DISTRIB_CODENAME="Vulcan"
DISTRIB_DESCRIPTION="Manjaro Linux"
libreoffice basic libreoffice-basic libreoffice-impress
1个回答
0
投票

您不必要地使任务复杂化了。不要通过 Interaction 运行宏,而是使用相邻的 Animation 上下文菜单项。

选择要更改颜色的对象,单击添加按钮。在 类别 字段中,选择 强调: 从效果列表中选择强调效果。在效果列表中找到“基本-更改填充颜色”。减少时间 Duration,例如减少到 0.01 秒,选择合适的绿色。

Settings

运行演示文稿的幻灯片并确保一切按预期进行。

顺便说一句,使用宏执行此任务是难以想象的困难 - 演示文稿没有告诉宏它是从哪个 Shape 启动的。而人工智能也无法应对这样的任务。

© www.soinside.com 2019 - 2024. All rights reserved.