How to create fading animation


This example demonstrates how to read and modify the transparency of a layer. The fading out of a layer in the current scene is animated by adjusting its transparency setting. Starting with the current transparency value, the symbols in the layer are recorded with increasing values towards 100, which represents full transparency.
The layer itself is then updated with the resulting transparency value so that it is consistent with the Layer Properties | Display tab value.

How to use

  1. Paste the code into an ArcScene or ArcMap VBA session and call the macro 'FadingAnimation'.
  2. Add a drawable layer into ArcScene.
  3. Run the macro 'FadingAnimation'.
[VBA]
Public Sub FadingAnimation()
    
    ' get first layer
    Dim g_pDoc As ISxDocument
    Set g_pDoc = ThisDocument
    
    Dim pScene As IScene
    Set pScene = g_pDoc.Scene
    Dim layerCount As Integer
    layerCount = pScene.layerCount
    
    Dim pLayer As ILayer
    Set pLayer = pScene.Layer(0)
    
    If (pLayer Is Nothing) Then
        Exit Sub
    End If
    
    ' get extension with 3D properties
    Dim pLayerExts As ILayerExtensions
    Set pLayerExts = pLayer
    
    Dim i As Long
    Dim p3DProps As I3DProperties
    For i = 0 To pLayerExts.ExtensionCount - 1
        If TypeOf pLayerExts.Extension(i) Is I3DProperties Then
            Set p3DProps = pLayerExts.Extension(i)
            Exit For
        End If
    Next i
    
    Dim bLighting As Boolean
    bLighting = p3DProps.Illuminate
    Dim bExtruded As Boolean
    If (p3DProps.ExtrusionType < > esriExtrusionNone) Then
        bExtruded = True
    Else
        bExtruded = False
    End If
    
    ' get layer's symbols in scene graph
    Dim pSG As ISceneGraph
    Set pSG = g_pDoc.Scene.SceneGraph
    
    Dim pSymArray As IArray
    Dim pDisplayListIDs As ILongArray
    pSG.GetOwnerSymbols pLayer, pSymArray, pDisplayListIDs
    
    ' read (and activate) layer's transparency
    Dim currentTransp As Long
    pSG.GetOwnerTransparency pLayer, currentTransp
    If (currentTransp = 0) Then
        pSG.SetOwnerTransparencyState pLayer, True
    End If
    
    ' fading animation
    Dim transp As Integer
    For transp = currentTransp To 100 ' transparency value loop
        Dim pSym As ISymbol
        Dim listID As Long
        Dim nSyms As Long
        Dim s As Long
        
        nSyms = pSymArray.Count
        For s = 0 To nSyms - 1 ' symbol recording loop
            Set pSym = pSymArray.Element(s)
            listID = pDisplayListIDs.Element(s)
            pSG.RecordSymbol pSym, listID, bExtruded, bLighting, transp, False
        Next s
        pSG.RefreshViewers
    Next transp
    
    ' set the layer as completely transparent, for consistency
    If TypeOf pLayer Is IDisplayFilterManager Then
        Dim pDLManager As IDisplayFilterManager
        Set pDLManager = pLayer
        If (Not pDLManager Is Nothing) Then
            Dim pDisplayFilter As ITransparencyDisplayFilter
            Set pDisplayFilter = New TransparencyDisplayFilter
            pDisplayFilter.Transparency = 255
            pDLManager.DisplayFilter = pDisplayFilter
        End If
    End If
    
    If TypeOf pLayer Is ILayerEffects Then
        Dim pLayerEffects As ILayerEffects
        Set pLayerEffects = pLayer
        pLayerEffects.Transparency = 100
    End If
    
End Sub