Copy link to clipboard
Copied
I have a collection of photos with count items created with the Count Tool in CS5 extended version. Each count item belongs to one of 5 count groups created with the Count Tool. Using the Photoshop COM, I can get the total number of count items per photo (Document.CountItems.Count()). However, I cannot get the number of count items per count group, or the group a count item belongs to. Has anybody had success in accessing count groups? I am using C#, but a solution in any language would be helpful.
Hi here are some functions on how to get the length of the counts for one group:
...
// examples:===================
alert("there are "+getCountsInGroup(getCurrentGroup()).length+ " counts in the selected countGroup");// getting the counts for the current selected group
//getCountsInGroup(0);//get counts for the first group
// ===================================
function getCountsInGroup( idx ){
var cArr = listCountsArr();
return cArr[idx];
}
function getCurrentGroup(){// find the index of
Copy link to clipboard
Copied
Hum the counters is an odd thing… It looks like it does all or nothing…?
If I change group visibility it does NOT change the count unless I do it to ALL…?
if any 1 group is visible the the count length is ALL…?
So using Adobe extendScript I can do this as alt…?
#target Photoshop
var doc = app.activeDocument;
for ( var i = 4; i >= 0; i-- ) { // Just a reverse remove
var allCounts = doc.countItems.length;
alert( ' All remaining Counters: ' + allCounts ); // All the doc counts…
selectCountGroup( i );
clearCountGroup();
var newCount = doc.countItems.length;
var grpCount = allCounts - newCount;
alert( 'Group ' + ( i + 1 ) + ' Counters: ' + grpCount )
};
// This has NO affect on count its either ALL || NOTHING
function countGroupVisible() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc130 = new ActionDescriptor();
desc130.putBoolean( cTID('Vsbl'), false );
executeAction( sTID('countGroupVisible'), desc130, DialogModes.NO );
};
//
function selectCountGroup( numb ) {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc133 = new ActionDescriptor();
desc133.putInteger( cTID('ItmI'), numb );
executeAction( sTID('countSetCurrentGroup'), desc133, DialogModes.NO );
};
//
function clearCountGroup() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc198 = new ActionDescriptor();
executeAction( sTID('countClear'), desc198, DialogModes.NO );
};
Copy link to clipboard
Copied
Hi here are some functions on how to get the length of the counts for one group:
// examples:===================
alert("there are "+getCountsInGroup(getCurrentGroup()).length+ " counts in the selected countGroup");// getting the counts for the current selected group
//getCountsInGroup(0);//get counts for the first group
// ===================================
function getCountsInGroup( idx ){
var cArr = listCountsArr();
return cArr[idx];
}
function getCurrentGroup(){// find the index of the selected group
var firstArr = listCountsArr();// make a list with arrays as grpoups and inside them objects for each count
addTempCount();// create a temp cont
var secArr = listCountsArr();// make a second list
theCGroup = 0;
for( i=0; i<firstArr.length; i++){// compare the listCountsArr
if( firstArr.length != secArr.length){
theCGroup = i;
break;
}
}
deleteCount( secArr[theCGroup][secArr[theCGroup].length - 1].idx + 1);// detele the temp count
return theCGroup;
}
function addTempCount(){
var desc = new ActionDescriptor();
desc.putDouble( charIDToTypeID( "X " ), 0 );
desc.putDouble( charIDToTypeID( "Y " ), 0 );
executeAction( stringIDToTypeID( "countAdd" ), desc, DialogModes.NO );
}
function deleteCount( idx ){
var desc = new ActionDescriptor();
desc.putInteger( charIDToTypeID( "ItmI" ), idx );
executeAction( stringIDToTypeID( "countDelete" ), desc, DialogModes.NO );
}
function listCountsArr(){
var cArr = new Array();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn") , charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc1 = executeActionGet(ref);
desc1 = desc1.getList(stringIDToTypeID('countClass'));
var crntG = 0;
var grpArr = new Array();
for(var i = 0; i<desc1.count; i++){
var gr = desc1.getObjectValue(i).getInteger(charIDToTypeID("Grup"));
var itI = desc1.getObjectValue(i).getInteger(charIDToTypeID("ItmI"));
var itX = desc1.getObjectValue(i).getUnitDoubleValue(charIDToTypeID("X "));
var itY = desc1.getObjectValue(i).getUnitDoubleValue(charIDToTypeID("Y "));
var cntObj = {idx:itI, x:itX, y:itY, grpIDX:gr, domI: i};
if(crntG == gr ){
grpArr.push(cntObj);
}
if(crntG != gr ){
cArr.push(grpArr);
grpArr = new Array();
grpArr.push(cntObj);
crntG = gr;
}
}
cArr.push(grpArr);
return cArr;
}
Copy link to clipboard
Copied
Muppet Mark's and cbuliarca's both worked- thanks for your replies! For the record, I ended up using this in C#:
ps.ApplicationClass app = new Photoshop.ApplicationClass();
app.Visible = false;
ps.Document doc = app.Open(str, null, false);
app.ActiveDocument = doc;
var Ref = new ps.ActionReference();
Ref.PutEnumerated(app.CharIDToTypeID("Dcmn"), app.CharIDToTypeID("Ordn"), app.CharIDToTypeID("Trgt"));
var desc1 = app.ExecuteActionGet(Ref);
var desc2 = desc1.GetList(app.StringIDToTypeID("countClass"));
int[] arrCounts = new int[5] { 0, 0, 0, 0, 0};
for (int i = 0; i < desc2.Count; i++)
{
int gr = desc2.GetObjectValue(i).GetInteger(app.CharIDToTypeID("Grup"));
arrCounts[gr] = arrCounts[gr] + 1;
}