redefinery

Paint

This section describes how to work with the Paint effect and brush strokes. The following topics are covered:


Retrieving all paint brush strokes on a layer

The Paint effect contains zero or more strokes (Brush properties of the Paint effect), which are properties of the Paint effect’s paint group PropertyGroup object.

The following code shows how to retrieve all paint brush strokes from all Paint effects on a layer, and store them in an array for retrieval or use elsewhere in your code.

// given:
// layer = Layer object, and the layer can have effects applied
//
var allPaintBrushes = new Array();               // Store brush strokes in an array
var effects = layer.property("Effects");         // Look for layers that can have effects
if (effects !== null)
{
    var effect, paintStrokes;
                                                 // Iterate over all effects on the layer
    for (var i = 1; i <= effects.numProperties; i++)
    {
        effect = effects.property(i);
        if (effect.matchName === "ADBE Paint")   // Look for Paint effects
        {
                                                 // Get PropertyGroup containing the strokes
            paintStrokes = effect.property("ADBE Paint Group");
                                                 // Store the brush strokes in the array
            for (var j = 1; j <= paintStrokes.numProperties; j++)
                allPaintBrushes[allPaintBrushes.length] = paintStrokes.property(j);
        }
    }
}
// The allPaintBrushes array now contains the list of brush strokes
// The number of brush strokes is allPaintBrushes.length

Retrieving the selected paint brush strokes on a layer

If your script needs to operate on the selected paint brush strokes on a layer, you need to check if the selected attribute for the brush stroke (Property) is true.

The following code shows how to iterate over the properties of a layer’s Paint effects, and store only the properties whose selected attribute is true in an array for retrieval or use elsewhere in your code. This code is very similar to the code for retrieving the paint brush strokes on a layer, with the extra check for the selected attribute value.

// given:
// layer = Layer object, and the layer can have effects applied
//
var selectedPaintBrushes = new Array();          // Store brush strokes in an array
var effects = layer.property("Effects");         // Look for layers that can have effects
if (effects !== null)
{
    var effect, paintStrokes, paintStroke;
                                                 // Iterate over all effects on the layer
    for (var i = 1; i <= effects.numProperties; i++)
    {
        effect = effects.property(i);
        if (effect.matchName === "ADBE Paint")   // Look for Paint effects
        {
                                                 // Get PropertyGroup containing the strokes
            paintStrokes = effect.property("ADBE Paint Group");
                                                 // Iterate over the brush strokes
            for (var j = 1; j <= paintStrokes.numProperties; j++)
            {
                                                 // Store only selected strokes in the array
                paintStroke = paintStrokes.property(j);
                if (paintStroke.selected)
                    selectedPaintBrushes[selectedPaintBrushes.length] = paintStroke;
            }
        }
    }
}
// The selectedPaintBrushes array now contains the list of selected paint brush strokes
// in top-to-bottom order