Skip to main content
Participant
May 22, 2020
Question

Photoshop Script Count Group Name

  • May 22, 2020
  • 1 reply
  • 1822 views

Hi,

I'm currently trying to export my count groups into a seperate file so that they can also be seen with simple image viewers.

This already works quite good, but I would like to use the name of the count group as part of my export filename.

Is there a way to get the count group name in my script? What would also be nice (but not necessarily required for my use case) is to get the color of the dots?

 

Thanks,

Lukas

 

What I already have:

 

    var ref = new ActionReference();
    ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID("countClass"));
    ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var Count = executeActionGet(ref).getList(stringIDToTypeID("countClass")).count

    for (var groupNum = 0; groupNum < 10; groupNum++) {
        var layer = undefined;
        for (var z = 0; z < Count; z++) {
            var Group = executeActionGet(ref).getList(stringIDToTypeID("countClass")).getObjectValue(z).getUnitDoubleValue(stringIDToTypeID("group"));
            if (Group == groupNum) {
                if (layer == undefined) {
                    layer = createLayer("count " + Group);
                }
                var X = executeActionGet(ref).getList(stringIDToTypeID("countClass")).getObjectValue(z).getUnitDoubleValue(stringIDToTypeID("x"));
                var Y = executeActionGet(ref).getList(stringIDToTypeID("countClass")).getObjectValue(z).getUnitDoubleValue(stringIDToTypeID("y"));
                // TODO extract color of dot to draw new circle
                my_circle(X, Y);
            }
        }
        if (layer != undefined) {
            // TODO use group name instead of groupNum for saveAs
            saveAs(groupNum);
            layer.remove();
        }
    }

 

 

This topic has been closed for replies.

1 reply

Kukurykus
Legend
May 22, 2020
activeDocument.layerSets.length
lukhasAuthor
Participant
May 22, 2020

This is 0 in my case.

Participant
August 23, 2022

Now I understand. You could create 'New Tool Preset...' and then read groups name from the file, but for some reason this option is greyed, so that may be bug, at least I think there is no any other tool with no option to do it 😕😕


So, just confirming here, there is no way to get the group name from the script? I tried 'typename' but that was just CountItem

 

 

We have 4 or 5 groups.

My script 

```

var ci = app.activeDocument.countItems
var plist = "ItemNumber\tXpos\tYpos\n"
var tp = Folder.desktop + "/CountItem.txt";
for (var i = 0; i < ci.length; i++){
var pos = ci[i].position.toString().split(",")
var group = ci[i].typename.toString()
plist += (i+1) + "\t" + pos[0] +"\t" + pos[1] + "\t" + group + "\n"
};

writeText(tp, plist)

/**
* Write a text file
* the file path
* the text
*
*/
function writeText(p,s){
var file = new File(p.toString());
file.encoding = 'UTF-8';
file.open('w');
file.write(s);
file.close();
}

```