Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

count pixels?

New Here ,
Nov 10, 2009 Nov 10, 2009

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!

TOPICS
Actions and scripting
932
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Nov 11, 2009 Nov 11, 2009

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

...
Translate
Adobe
Valorous Hero ,
Nov 11, 2009 Nov 11, 2009

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;
};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 11, 2009 Nov 11, 2009

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Nov 11, 2009 Nov 11, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 11, 2009 Nov 11, 2009
LATEST

You guys are great! This worked. Thank you so much. You have literally saved me thousands of hours, I'm sure!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines