Copy link to clipboard
Copied
Hi All,
How to read the below highlighted value in script. Pl help me.
Regards,
RockSel
Hi Rock Sel,
Try the below js code.
var myDoc = app.activeDocument.pages.everyItem().textFrames.everyItem();
try{
var myCharlength = myDoc.characters.length;
}catch(e){}
if(myCharlength<=0){
alert("Characters count is 0 in this document!");
}
else{
alert("Characters count : "+myCharlength);
}
thx
csm_phil
Copy link to clipboard
Copied
Your script take some time for long texts (300 pages), but it rocks !
I like the possibility to exclude hidden layers, perfect for exclude some notes in marges, just have to put them on another layer, hide it then count the total.
With your settings, the script can help for several cases.
Does it include tables ? (I think so, but I haven't some to be sure of that)
Thanks a lot,
Anthony
Copy link to clipboard
Copied
@Anthony – yes, it does count characters in tables.
And characters of tables sitting in tables.
The script uses InDesign's GREP search, so this functionality is implicitly built into.
Uwe
Copy link to clipboard
Copied
AI generated Javascript that counts only visible text elements. It counts both characters and empty space, but not line breaks. Put the needed elements into one layer and hide the others, before making a count. Hope its relevant
<code>
(function ()
{ if (app.documents.length === 0) {
alert("No open documents");
return;
}
var doc = app.activeDocument;
var visibleText = "";
// Check all layers are visible
for (var i = 0; i < doc.layers.length; i++){
var layer = doc.layers[i];
if (layer.visible) { // Only visible layers
var textFrames = layer.textFrames;
for (var j = 0; j < textFrames.length; j++) {
visibleText += textFrames[j].contents; // Only add tet from visible layers
}
}
}
var cleanedText = visibleText.replace(/[\r\n]/g, ""); // Remove line break
var charCount = cleanedText.length; // Characters incl. word space
alert("Number of characters (incl. word space, ex. line break, only visible layers): " + charCount); })();
</code>
Copy link to clipboard
Copied
Not really.
You don't have to put "needed elements into one layer and hide the others" - as this script will count elements from all visible layers anyway.
This comment is misleading:
// Check all layers are visible
It's not what this loop is doing.
And overall - it's not optimal - instead of building bigger and bigger string - it could count number of characters for each element and increase total counter.
Also, it doesn't count texts in Tables.
And the thread is 13 years old...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now