如何在选择上创建淡入淡出效果?

How to create a fade in effect on the selection?

关于宏,Impress做的很少(没有宏记录,没有Python脚本,只有Basic等),样本也很少。

没有如何创建 "manually" 文本动画的示例。我找到了一个 here(6 岁)并且有很多信息。

到目前为止,我已经设法 (1) 扫描已经存在的文本动画 "fadein" (2) 扫描所有其他文本动画,然后将它们删除并替换为克隆"fadein" 动画:

sub MyFunction
    ' --------------------------------------------------------------------
    ' (1) scan for a text animation "fadein" that is already there
    effectNodeFadeIn = Null
    doc = ThisComponent
    numSlides = doc.getDrawPages().getCount()
    slide = doc.drawPages(numSlides-1)

    mainSequence = getMainSequence(slide)    
    clickNodes = mainSequence.createEnumeration()
    while clickNodes.hasMoreElements() and IsNull(effectNodeFadeIn)
        clickNode = clickNodes.nextElement()

        groupNodes = clickNode.createEnumeration()
        while groupNodes.hasMoreElements() and IsNull(effectNodeFadeIn)
            groupNode = groupNodes.nextElement()

            effectNodes = groupNode.createEnumeration()
            while effectNodes.hasMoreElements() and IsNull(effectNodeFadeIn)
                effectNode = effectNodes.nextElement()
                ' ICIC

                if effectNode.ImplementationName = "animcore::ParallelTimeContainer" then
                    if hasUserDataKey(effectNode, "preset-id") then
                        v = getUserDataValue(effectNode, "preset-id")
                        if v = "ooo-entrance-fade-in" then ' ooo-entrance-appear
                            effectNodeFadeIn = effectNode
                        end if
                    end if
                end if
                ' useless loop just in case I need it:
                animNodes = effectNode.createEnumeration()
                while animNodes.hasMoreElements()
                    animNode = animNodes.nextElement()
                wend
            wend
        wend
    wend
    ' --------------------------------------------------------------------
    ' (2) scan for all other text animations, 
    ' and then remove them an replace them by a clone of the "fadein" animation
    if not IsNull(effectNodeFadeIn) then

        clickNodes = mainSequence.createEnumeration()
        while clickNodes.hasMoreElements()
            clickNode = clickNodes.nextElement()

            groupNodes = clickNode.createEnumeration()
            while groupNodes.hasMoreElements()
                groupNode = groupNodes.nextElement()

                effectNodes = groupNode.createEnumeration()
                while effectNodes.hasMoreElements()
                    effectNode = effectNodes.nextElement()
                    ' ICIC

                    if effectNode.ImplementationName = "animcore::ParallelTimeContainer" then
                        if hasUserDataKey(effectNode, "preset-id") then
                            v = getUserDataValue(effectNode, "preset-id")
                            if v <> "ooo-entrance-fade-in" then ' ooo-entrance-appear
                                groupNode.removeChild(effectNode)
                                n = effectNodeFadeIn.createClone()
                                groupNode.appendChild(n)

                                ' useless loop just in case I need it:
                                animNodes = effectNode.createEnumeration()
                                while animNodes.hasMoreElements()
                                    animNode = animNodes.nextElement()
                                wend
                            end if
                        end if

                    end if
                wend
            wend
        wend
    end if
end sub

function hasUserDataKey(node as Object, key as String) as Boolean
    for each data in node.UserData
        if data.Name = "node-type" then
            hasUserDataKey = True
            exit function
        end if
    next data
    hasUserDataKey = False
end function

function getUserDataValue(node as Object, key as String) as Variant
    for each data in node.UserData
        if data.Name = key then
            getUserDataValue = data.Value
            exit function
        end if
    next data
end function

当我克隆效果时,它仍然是 "linked" 到原始文本,然后父级被删除并替换为 "fadein" 文本。知道如何纠正这个问题吗?

听起来您选择了形状内部的文本,因此使用如下基本代码:

Sub AddAnimation
    xTextCursor = ThisComponent.CurrentController.Selection(0)
    xText = xTextCursor.getText()
    xText.TextEffect = com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM
End Sub

或在python:

import uno
from com.sun.star.presentation.AnimationEffect import FADE_FROM_BOTTOM

def add_animation():
    oDoc = XSCRIPTCONTEXT.getDocument()
    xTextCursor = oDoc.CurrentController.Selection.getByIndex(0)
    xText = xTextCursor.getText()
    xText.TextEffect = FADE_FROM_BOTTOM

由于我不完全清楚的原因,结果是擦除而不是淡入。

文档位于 https://wiki.openoffice.org/wiki/Documentation/DevGuide/Drawings/Animations_and_Interactions. The ShapeHelper class from that page is defined in ShapeHelper.java