0

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

没有示例如何“手动”创建文本动画。我在这里找到了一个(6 岁)并且有很多信息。

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

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

当我克隆效果时,它仍然“链接”到原始文本,然后父级被删除并替换为“淡入淡出”文本。知道如何纠正这个问题吗?

4

1 回答 1

0

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

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。该ShapeHelper页面中的类在ShapeHelper.java中定义。

于 2017-03-29T21:57:52.647 回答