Skip to main content
sergiopop75
Inspiring
May 23, 2022
Question

Select by color

  • May 23, 2022
  • 1 reply
  • 2152 views

It's possible to select objects by color. It is for the option to select a scene of strokes with different colors. I want to select all those with the same color with edit multiple frames.

    This topic has been closed for replies.

    1 reply

    n. tilcheff
    Legend
    May 23, 2022

    Depending on what you want to do to those strokes, you may be able to use Find And Replace Strokes.

     

    Nick - Character Designer and Animator, Flash user since 1998 | Member of the Flanimate Power Tools team - extensions for character animation
    sergiopop75
    Inspiring
    May 23, 2022

    I have tried, but the option is to select the stroke with green color and delete. And keep the red stroke.
    Thanks!

    ____2D vector animator since 2000 & PhD
    sergiopop75
    Inspiring
    May 23, 2022

    I found this code that works in Flash CS6, but not in Animate 2021-22

     

    var dom = fl.getDocumentDOM();
    var timeline = dom.getTimeline();
    
    /*
     MODIFY THE KEYS IN THIS TABLE.
     */
    var coloursToDelete = {
        'FF0000': true,
        'FFFF00': true,
    };
    
    var replacements;
    var srcColour;
    var layerName;
    
    // Make sure all colours are lowercase and start with a #
    for(var colour in coloursToDelete)
    {
        var val = coloursToDelete[colour];
        delete coloursToDelete[colour];
        
        if(colour[0] !== '#')
            colour = '#' + colour;
        
        coloursToDelete[colour.toLowerCase()] = val;
    }
    
    // Make sure to clear the selection, or the script will crash?
    dom.selectNone();
    
    fl.outputPanel.clear();
    
    var deleteCount = 0;
    
    // ----------------------------------------------------
    // Loop through all layers
    for(var layerIndex in timeline.layers)
    {
        var layer = timeline.layers[layerIndex];
        
        if(!layer.visible)
            continue;
        
        // ----------------------------------------------------
        // Loop through all frames of the current layer
        for(var frameIndex = 0; frameIndex < timeline.frameCount; frameIndex++)
        {
            var frameDeleteCount = 0;
            var frame = layer.frames[frameIndex];
            
            if(!frame)
                continue;
            
            // ----------------------------------------------------
            // Loop through all elements in the current frame
            for(var elementIndex in frame.elements)
            {
                var element = frame.elements[elementIndex];
                
                if(!element)
                    continue;
                
                if(element.elementType !== 'shape')
                    continue;
                
                // ----------------------------------------------------
                // Check each edge in the current shape
                for(var edgeIndex in element.edges)
                {
                    var edge = element.edges[edgeIndex];
                    var stroke = edge.stroke;
                    var fill = stroke ? stroke.shapeFill : null;
                    
                    if(!fill)
                        continue;
                    
                    if(fill.color in coloursToDelete)
                    {
                        stroke.shapeFill = null;
                        edge.stroke = fill;
                        deleteCount++;
                        frameDeleteCount++;
                    }
                }
            }
            
            // A quirk of deleting strokes like this is that shapes won't automatically merge like they would when deleting a stroke in the editor.
            // Selecting then deselecting will force this to happen
            if(frameDeleteCount > 0)
            {
                dom.selectAll();
                dom.selectNone();
            }
        }
    }
    
    fl.trace('-- ' + dom.name + ': Deleted ' + (deleteCount) + ' strokes.');

     

    ____2D vector animator since 2000 &amp; PhD