8 Replies Latest reply on Feb 27, 2008 3:34 PM by marcusstringer

    [JS] Help Locating TextCount.js

    marcusstringer Level 3
      Hi Guys,
      I am trying locate TextCount.js
      It google says It should be in the Goodies folder of the instal cd.

      I've looked in my CS Package without luck, also CS2 and CS3

      Would anyone know where it is?
      Or be able to port the code here for me please.

      Or know of a text character counter which does side notes and overset text and unlinked stories???

      Thanks
      Marcus
        • 1. Re: [JS] Help Locating TextCount.js
          marcusstringer Level 3
          Does anyone know where I can find this please????
          • 2. Re: [JS] Help Locating TextCount.js
            marcusstringer Level 3
            Does Anyone know?????
            • 3. Re: [JS] Help Locating TextCount.js
              Level 1
              Apparently not. There were no scripts included with CS, if memory serves. Have you check the Adobe Exchange?

              Dave
              • 4. Re: [JS] Help Locating TextCount.js
                Peter Kahrel Adobe Community Professional & MVP
                Do a google on textcount.js and you get numerous references that say that that script is on the CS2 installation disks.

                Peter
                • 5. Re: [JS] Help Locating TextCount.js
                  marcusstringer Level 3
                  No, It says that the script is installed on the InDesign Installation disk, it doesn't say if it was on the CS Installation Disks...Because I have all the CS's and it's not on there I was hoping someone may have the stand-a-long InDesign CS2 Installation CD and could post the script here.

                  this is the only thing that comes up with a google search:

                  <!-- Original: Ronnie T. Moore -->
                  <!-- Dynamic 'fix' by: Nannette Thacker -->

                  function textCounter(field, countfield, maxlimit) {

                  if (field.value.length > maxlimit) {

                  // if too long...trim it!
                  field.value = field.value.substring(0, maxlimit);

                  alert( 'This field is limited to ' + maxlimit + ' characters in length.' );

                  } else {

                  // otherwise, update 'characters left' counter
                  countfield.value = maxlimit - field.value.length;

                  }
                  }

                  I don't know if that's the complete code or not... It seems too short...
                  But that's all I could find.

                  If anyone has any ideas, this would be such great production tool... because I haven't found anything which will could count the number of words in an InDesign document yet.
                  • 6. Re: [JS] Help Locating TextCount.js
                    Harbs. Level 6
                    For a simple one check here:
                    http://mysite.verizon.net/zevt/index_files/WordCount.htm

                    And this is what I found on a search on my computer...


                    //TextCounter
                    //An InDesign 3 JavaScript
                    //
                    //Counts text objects in the selection, in the selected story, or in all
                    stories in a document.
                    //
                    //For more on InDesign scripting, go to
                    http://www.adobe.com/products/indesign/scripting.html
                    //or visit the InDesign Scripting User to User forum at
                    http://www.adobeforums.com
                    //
                    if(app.documents.length != 0){
                    if(app.activeDocument.stories.length > 0){
                    myDisplayDialog();
                    }
                    else{
                    alert("The current document does not contain any text.");
                    }
                    }
                    else{
                    alert("No documents are open. Please open a document and try again.");
                    }

                    function myDisplayDialog(){
                    var myCountButtons, myRangeButtons;
                    var myDialog = app.dialogs.add({name:"TextCounter"});
                    with(myDialog.dialogColumns.add()){
                    with(borderPanels.add()){
                    staticTexts.add({staticLabel:"Count:"});
                    with(myCountButtons = radiobuttonGroups.add()){
                    radiobuttonControls.add({staticLabel:"Characters"});
                    radiobuttonControls.add({staticLabel:"Words",
                    checkedState:true});
                    radiobuttonControls.add({staticLabel:"Lines"});
                    radiobuttonControls.add({staticLabel:"Paragraphs"});
                    }
                    }
                    with(borderPanels.add()){
                    staticTexts.add({staticLabel:"Range:"});
                    with(myRangeButtons = radiobuttonGroups.add()){
                    radiobuttonControls.add({staticLabel:"Selection",
                    checkedState:true});
                    radiobuttonControls.add({staticLabel:"Selected Story"});
                    radiobuttonControls.add({staticLabel:"All Stories"});
                    }
                    }
                    }
                    var myReturn = myDialog.show();
                    if (myReturn == true){
                    //Get the values from the dialog box.
                    var myRangeType = myRangeButtons.selectedButton;
                    var myCountType = myCountButtons.selectedButton;
                    myDialog.destroy();
                    myTextCounter(myRangeType, myCountType);
                    }
                    else{
                    myDialog.destroy();
                    }
                    }
                    function myTextCounter(myRangeType, myCountType){
                    var myDocument, myTextCount, mySelection, myCountingUnit;
                    with (myDocument = app.activeDocument){
                    //Set the AlreadyCounted key of any stories in the document to
                    false.
                    for (var myStoryCounter = 0; myStoryCounter <
                    myDocument.stories.length; myStoryCounter ++){

                    myDocument.stories.item(myStoryCounter).insertLabel("AlreadyCounted",
                    "False")
                    }
                    switch (myRangeType){
                    case 0:
                    //Count the text in the selection.
                    //If multiple text frames are selected, all of the
                    //text in the frames will be counted.
                    mySelection = selection;
                    if (mySelection.length == 1){
                    myTextCount = mySelectionSorter(mySelection[0],
                    myRangeType, myCountType);
                    }
                    else{
                    myTextCount = 0;
                    for (var myCounter = 0; myCounter <
                    mySelection.length; myCounter++){
                    myTextCount = myTextCount +
                    mySelectionSorter(mySelection[myCounter], myRangeType, myCountType);
                    }
                    }
                    break;
                    case 1:
                    //Count the text in the parent story (or stories) of the
                    selection)
                    mySelection = selection;
                    if (mySelection.length == 1){
                    myTextCount = mySelectionSorter(mySelection[0],
                    myRangeType, myCountType);
                    }
                    else{
                    myTextCount = 0;
                    //Now iterate through the items and count the text.
                    for (var myCounter = 0; myCounter <
                    mySelection.length; myCounter++){
                    myTextCount = myTextCount +
                    mySelectionSorter(mySelection[myCounter], myRangeType, myCountType);
                    }
                    }
                    break;
                    case 2:
                    //Count the text in all stories of the active document.
                    myTextCount = 0;
                    for(var myStoryCounter = 0; myStoryCounter <
                    myDocument.stories.length; myStoryCounter ++){
                    myTextCount = myTextCount +
                    myCountText(myDocument.stories.item(myStoryCounter), myCountType);
                    }
                    break;
                    }
                    switch(myCountType){
                    case 0:
                    if (myTextCount == 1){
                    myCountingUnit = "character";
                    }
                    else {
                    myCountingUnit = "characters";
                    }
                    break;
                    case 1:
                    if (myTextCount == 1){
                    myCountingUnit = "word";
                    }
                    else {
                    myCountingUnit = "words";
                    }
                    break;
                    case 2:
                    if (myTextCount == 1){
                    myCountingUnit = "line";
                    }
                    else {
                    myCountingUnit = "lines";
                    }
                    break;
                    case 3:
                    if (myTextCount == 1){
                    myCountingUnit = "paragraph";
                    }
                    else {
                    myCountingUnit = "paragraphs";
                    }
                    break;
                    }
                    var myDialog = app.dialogs.add({name:"TextCounter",
                    canCancel:false});
                    with(myDialog){
                    //Add a dialog column.
                    with(dialogColumns.add()){
                    with(borderPanels.add()){
                    staticTexts.add({staticLabel:"InDesign found "});
                    with(dialogColumns.add()){
                    textEditboxes.add({editContents:myTextCount+""});
                    }
                    with(dialogColumns.add()){
                    staticTexts.add({staticLabel:myCountingUnit});
                    }
                    }
                    }
                    }
                    myDialog.show();
                    myDialog.destroy();
                    }
                    }
                    function mySelectionSorter(myObject, myRangeType, myCountType){
                    var myTextCount;
                    switch (myObject.constructor.name){
                    case "Text":
                    case "InsertionPoint":
                    switch (myRangeType){
                    case 0:
                    myTextCount = myCountText(myObject, myCountType);
                    break;
                    case 1:
                    myTextCount = myCountText(myObject.parentStory,
                    myCountType);
                    break;
                    }
                    break;
                    case "TextFrame":
                    switch (myRangeType){
                    case 0:
                    myTextCount = myCountText(myObject.texts.item(0),
                    myCountType);
                    break;
                    case 1:
                    //Has the parent story already been counted?
                    myStory = myObject.parentStory;
                    myCountedState = myStory.extractLabel("AlreadyCounted");
                    if (myCountedState != "True"){
                    myTextCount = myCountText(myStory, myCountType);
                    myStory.insertLabel("AlreadyCounted", "True");
                    }
                    else {
                    myTextCount = 0;
                    }
                    break;
                    }
                    break;
                    default:
                    //Selection is a not a text object.
                    //There's still a chance it could be a textPath object.
                    if (myObject.textPaths.length !=0){
                    myTextCount = 0;
                    if (myRangeType == 1){
                    for (myTextPathCounter = 0; myTextPathCounter <
                    myObject.textPaths.length; myTextPathCounter ++){
                    myStory =
                    myObject.textPaths.item(myTextPathCounter).parentStory;
                    myCountedState =
                    myStory.extractLabel("AlreadyCounted");
                    if (myCountedState != "True"){
                    myTextCount = myTextCount +
                    myCountText(myObject.textPaths.item(myTextPathCounter).parentStory,
                    myCountType);

                    myObject.textPaths.item(myTextPathCounter).parentStory.insertLabel("AlreadyCounted","True" );
                    }
                    else{
                    myTextCount = 0;
                    }
                    }
                    }
                    else {
                    for (myTextPathCounter = 0; myTextPathCounter <
                    myObject.textPaths.length; myTextPathCounter ++){
                    myTextCount = myTextCount +
                    myCountText(myObject.textPaths.item(myTextPathCounter).texts.item(0),
                    myCountType);
                    }
                    }
                    }
                    else {
                    myTextCount = 0;
                    }
                    break;
                    }
                    return myTextCount;
                    }
                    function myCountText(myTextObject, myCountType){
                    var myTextCount;
                    switch(myCountType){
                    case 0:
                    //count characters
                    myTextCount = myTextObject.characters.length;
                    break;
                    case 1:
                    //count words
                    myTextCount = myTextObject.words.length;
                    break;
                    case 2:
                    //count lines
                    myTextCount = myTextObject.lines.length;
                    break;
                    case 3:
                    //count paragraphs
                    myTextCount = myTextObject.paragraphs.length;
                    break;
                    }
                    return myTextCount;
                    }
                    • 7. Re: [JS] Help Locating TextCount.js
                      marcusstringer Level 3
                      That's fantastic...Thanks

                      Except it falls over at this line (first line)????
                      if(app.documents.length != 0){
                      • 8. Re: [JS] Help Locating TextCount.js
                        marcusstringer Level 3
                        Ignore that last message...I got it to work...Thanks so much...

                        Your a life saver