Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to insert characters count info in text frame

Return to Member Forum

  • Author
    Posts
    • #86463

      Hi.

      I need to point in some layouts how many characters were used in each text frame. I’ve made a script that include it before the text (see below) but I was thinking and maybe create a new text frame right over the original, with kind of a pink background and with the char count info. Do you have any suggestion in how to do that?

      Thanks,
      Luiz

      ———

      myDoc = app.activeDocument

      var myDoc = app.activeDocument;
      tf = app.activeDocument.textFrames;
      for(var i = 0; i<tf.length; i++){
      textFrame = tf[i];

      tamanho = textFrame.characters.length;
      textFrame.insertionPoints[0].contents = tamanho + ” characters. “;

      }

    • #86464

      Hi.

      I’ve found a way. I’m pasting it below just in case someone want to use it or maybe improve it.

      Thanks,
      Luiz

      —-
      myDoc = app.activeDocument
      var myDoc = app.activeDocument;

      // create arrays to save frame infos
      var xizes = [];
      var xizes2 = []
      var ipes = [];
      var ipes2 = [];
      var valors = [];
      var valorsw = [];

      // get frame infos (position and text lenght)
      tf = app.activeWindow.activePage.textFrames;
      var fim = tf.length;

      for(var i = 0; i<fim; i++){
      textFrame = tf[i];
      tamanho = textFrame.characters.length;
      palavras = textFrame.words.length;
      par = textFrame.paragraphs.length;

      // the locations for the textframe
      var sp = 5;
      var y1 = textFrame.geometricBounds[0] – sp;
      var x1 = textFrame.geometricBounds[1];
      var y2 = textFrame.geometricBounds[2] – sp;
      var x2 = textFrame.geometricBounds[3] – sp;
      xizes[xizes.length] = x1;
      ipes[ipes.length] = y1;
      xizes2[xizes2.length] = x2;
      ipes2[ipes2.length] = y2;
      valors[valors.length] = tamanho;
      valorsw[valorsw.length] = palavras;

      }

      // create one frame for each existing, in a position a little different, showing char count
      var main = function() {

      var doc = app.activeDocument;
      // set the origin to the page
      var curr_origin = doc.viewPreferences.rulerOrigin;
      doc.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;

      tf = app.activeWindow.activePage.textFrames;
      var ende = tf.length;

      for(var g = 0; g < ende ; g++){

      var content = “Chars: ” + valors[g] + ” Words: ” + valorsw[g];

      // create the textframe
      var tf = app.activeWindow.activePage.textFrames.add({
      contents: content,
      geometricBounds: [ipes[g], xizes[g], ipes2[g], xizes2[g]]
      });
      // apply style: I’ve made one with a PINK shading to simulate a box
      tf.paragraphs[0].appliedParagraphStyle = doc.paragraphStyles.item(“myStyle”);

      }

      doc.viewPreferences.rulerOrigin = curr_origin;

      };
      main();

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
Forum Ads