8 Replies Latest reply on Nov 16, 2015 11:24 AM by pixxxel schubser

    Font Size

    LeoMari Level 2

      Hello everyone!

      I have a script that replaces sources.

      // fonts to replace
      var substitutions = [
        ['Arial', 'Regular',         'Helvetica Neue LT Std', '45 Light'],
      ];
      //  turn the substitutions into real fonts
      var subsRight = [];
      var fontCount = textFonts.length;
      var subsCount = substitutions.length;
      for (var i = 0; i < fontCount; i++) {
        var font = textFonts[i];
        for (var j = 0; j < subsCount; j++) {
          if (substitutions[j][2] == font.family && substitutions[j][3] == font.style) {
            subsRight[j] = font;
          }
        }
      }
      
      
      // replace the font
        var frames = doc.textFrames;
        for ( var j = 0; j < frames.length; j++ ) {
          var ranges = frames[j].textRanges;
          for ( var k = 0; k < ranges.length; k++ ) {
            var range = ranges[k];
            for (var f = 0; f < subsCount; f++) {
              if (range.characterAttributes.textFont.family == substitutions[f][0] 
                && range.characterAttributes.textFont.style == substitutions[f][1]) {
                range.characterAttributes.textFont = subsRight[f];
              }
            }
          }
        }
        redraw();
      

       

      I must now replace the size. 10 to 9.5pt and from 8 to 6.5pt.

      I believe it is possible but I'm still trying.

       

      I appreciate if you can help.

      Thank's!

        • 1. Re: Font Size
          Silly-V Adobe Community Professional

          Add range.characterAttributes.size to your script to control the size.

          • 2. Re: Font Size
            LeoMari Level 2

            Whew, I can!! hehehe

             

            var idoc = app.activeDocument; 
            for (i=1; i<idoc.textFrames.length; i++) 
                { 
                    var itext = idoc.textFrames[i]; 
                    var itextAttributes = itext.textRange.characterAttributes; 
                    if (itextAttributes.size == 8) 
                        itextAttributes.size = 6.5; 
              } 
            
            
            var idoc = app.activeDocument; 
            for (i=0; i<idoc.textFrames.length; i++) 
                { 
                    var itext = idoc.textFrames[i]; 
                    var itextAttributes = itext.textRange.characterAttributes; 
                    if (itextAttributes.size == 10) 
                        itextAttributes.size = 9.5; 
              } 
            
            • 3. Re: Font Size
              W_J_T Level 4

              No need to use two loops and declare everything twice, it's pointless. Also when someone points you in the right direction to solve your task its more appropriate to give them credit than give yourself credit.

              • 4. Re: Font Size
                pixxxel schubser Level 5

                Ok, this is one version.

                 

                But why you loop twice? This will double the time for execution.

                Why your first counter is i=1 and the second is i=0 ?

                 

                Furthermore: if you loop forward sometimes you can get an empty textframe --> then your script gets an error.

                 

                Better you try something like this:

                var aDoc = app.activeDocument;
                var theTF = charAttr = null;
                for ( i = aDoc.textFrames.length-1; i >= 0; i--) {
                    theTF = aDoc.textFrames[i];
                    if (theTF.textRange.contents) {
                    charAttr = theTF.textRange.characterAttributes;
                    if (charAttr.size == 10) {
                        charAttr.size = 9.5;
                        } else {
                            if (charAttr.size == 8) {
                                charAttr.size = 6.5;
                                }
                            }
                        }
                    }
                

                 

                regards

                 

                • 5. Re: Font Size
                  Silly-V Adobe Community Professional

                  pointses.jpg

                  • 6. Re: Font Size
                    LeoMari Level 2

                    W_J_T I resolved my problem yourself, although not the most correct was what I got. I saw the Silly statement when I was doing my second post, so the credit is mine, okay?

                    I hope it be clear ..

                    • 7. Re: Font Size
                      LeoMari Level 2

                      Thank you for improving, pixxxel schubser.

                      I am still learning. His answer is worth 10 points ..

                      • 8. Re: Font Size
                        pixxxel schubser Level 5

                         

                         

                        We are all still learning – every time. You're welcome.