Copy link to clipboard
Copied
I'm new to scripting and find it so confusing. i was wondering if anybody here would know where i could find a script for exporting histogram information? basically, i have hundreds of files with 30+ layers in each file. i need to know how many pixels are present on each layer. manually, i would do this by selecting each layer and check the pixels in the selected layer in the histogram palette and write it down. if, instead, i could export this info to either a database or word file, that would save me loads of time. i'm working on with CS2. thankful for any help!
You could try this, it will write the layer name and pixel count to a csv on the desktop with the same name as the open document.
...if(documents.length){
doc=activeDocument;
var area = activeDocument.histogram;
var Results=[];
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var CSV=File("~/desktop/"+Name+".csv");
findLayers(doc);
Results = Results.reverse();
CSV.open("w");
for(var a in Results){
CSV.writeln(Results[0]+","+Results[1]);
}
CSV.close();
}function findLayers(obj){
if(obj.artLayers.len
Copy link to clipboard
Copied
You could try this, it will write the layer name and pixel count to a csv on the desktop with the same name as the open document.
if(documents.length){
doc=activeDocument;
var area = activeDocument.histogram;
var Results=[];
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var CSV=File("~/desktop/"+Name+".csv");
findLayers(doc);
Results = Results.reverse();
CSV.open("w");
for(var a in Results){
CSV.writeln(Results[0]+","+Results[1]);
}
CSV.close();
}function findLayers(obj){
if(obj.artLayers.length>0){
for(var z = 0;z<obj.artLayers.length;z++){
if(obj.artLayers.kind == LayerKind.NORMAL) {
if(!obj.artLayers.isBackgroundLayer){
activeDocument.activeLayer=obj.artLayers;
loadSelection();
if(hasSelection ()){
Results.push([[activeDocument.activeLayer.name],[Histogram(activeDocument.histogram)]]);
activeDocument.selection.deselect();
}else{
Results.push([[activeDocument.activeLayer.name],[0]]);
}
}
}
}
}
if(obj.layerSets.length > 0){
for(var l=0;l<obj.layerSets.length;l++){
findLayers(obj.layerSets);
}
}
}
function Histogram(hist) {
var cnt = 0;
for (var i = 0; i < hist.length; i++) {
cnt += hist;
}
return cnt;
}
function loadSelection() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc57 = new ActionDescriptor();
var ref27 = new ActionReference();
ref27.putProperty( cTID('Chnl'), cTID('fsel') );
desc57.putReference( cTID('null'), ref27 );
var ref28 = new ActionReference();
ref28.putEnumerated( cTID('Chnl'), cTID('Chnl'), cTID('Trsp') );
desc57.putReference( cTID('T '), ref28 );
executeAction( cTID('setd'), desc57, DialogModes.NO );
};
function hasSelection (doc) {
if(doc == undefined) doc = activeDocument;
var res = false;
var as = doc.activeHistoryState;
doc.selection.deselect();
if (as != doc.activeHistoryState) {
res = true;
doc.activeHistoryState = as;
}
return res;
};
Copy link to clipboard
Copied
Thank you, Paul! I appreciate your help and the time you took out to do this. I received an error while running the script, but this will definitely give me a headstart! Thanks again.
Copy link to clipboard
Copied
There is one typo, Paul must have pressed the space bar when the cursor was in the wrong place.
Results.push([[activeDocument.activeLayer.name],[Histogram(activeDocument.histogram)]]);
Edit: Maybe Paul didn't make the typo, the forum seems to be inserting the space in histogram
Copy link to clipboard
Copied
You guys are great! This worked. Thank you so much. You have literally saved me thousands of hours, I'm sure!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now