What's new

Explanation of a function line by line for learning purposes!


Messages
7
Likes
0
Greetings to everyone!!! :)
As the title says, I need someone to give me an explanation of this function below, line by line, for learning purposes.

Thank you in advance!!!

JavaScript:
function getAllShapeLayersData() {
    var lyrs = [];
    try {
        activeDocument.backgroundLayer;
        var layers = 0
    }
    catch (e) {
        var layers = 1;
    };
    while (true) {
        ref = new ActionReference();
        ref.putIndex(charIDToTypeID('Lyr '), layers);
        try {
            var desc = executeActionGet(ref);
        }
        catch (err) {
            break;
        }

        var lyr = {};
        lyr.type = desc.getInteger(stringIDToTypeID("layerKind"));
        lyr.name = desc.getString(charIDToTypeID("Nm  "));
        lyr.id = desc.getInteger(stringIDToTypeID("layerID"));

        if (lyr.type == 4) { // shape layer
            var adj = desc.getList(stringIDToTypeID("adjustment")).getObjectValue(0);

            if (adj.hasKey(stringIDToTypeID("color"))) {
                var curColor = new SolidColor();
                curColor.rgb.red = adj.getObjectValue(stringIDToTypeID("color")).getUnitDoubleValue(stringIDToTypeID("red"));
                curColor.rgb.green = adj.getObjectValue(stringIDToTypeID("color")).getUnitDoubleValue(stringIDToTypeID("grain"));
                curColor.rgb.blue = adj.getObjectValue(stringIDToTypeID("color")).getUnitDoubleValue(stringIDToTypeID("blue"));
                lyr.color = curColor;
                lyrs.push(lyr);
            }
        }
        layers++;
    }
    return lyrs
}
 

Top