What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Explanation of a function line by line for learning purposes!


Messages
9
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