9 Replies Latest reply on Jul 24, 2017 12:56 PM by williamadowling

    Use applescript to delete text based on point size

    mandip94728536

      I need to create a script that will delete all text in an Illustrator document that is larger than 70 points. All of my attempts have resulted in errors saying the item can not be deleted or adobe illustrator "can't get size"

       

      I found a script in another forum (Select Objects based on font size or other criteria? )that creates a dialogue box asking for a point size range. When you put in the range it selects type within the range. This works really well but I need to run this script on a large number of files and manually inputting the size range each time is time consuming.

       

      Any help would be appreciated. Thanks so much

        • 1. Re: Use applescript to delete text based on point size
          williamadowling Level 4

          I took the exact script you posted a link to and just removed the dialog box and the range functionality (so instead of being between 2 numbers, it's just anything greater than 70pt). Sorry it's not applescript.. but you're better off with javascript anyway. It's cross platform and has much more control over the Illustrator DOM than applescript does.

           

          This is probably not an elegant way of doing this, but i gave it a brief test and it seems to work. It only selects the art though. If you want to delete all of the selection, just uncomment the for loop at the bottom and it will delete the entire selection array.

           

          function container()
          {
              var maxPointSize = 70;
              selectTextWhosePointSizeIs(maxPointSize);
          
          
              function selectTextWhosePointSizeIs(maxPointSize)
              {
                  var doc, tfs, i = 0,
                      n = 0,
                      selectionArray = [];
          
          
                  if (!app.documents.length)
                  {
                      return;
                  }
          
          
                  doc = app.activeDocument;
                  tfs = doc.textFrames;
                  n = tfs.length;
          
          
                  doc.selection = null;
          
          
                  if (!n)
                  {
                      return;
                  }
          
          
                  for (i = 0; i < n; i++)
                  {
                      if (tfs[i].textRange.size > maxPointSize)
                      {
                          selectionArray[selectionArray.length] = tfs[i];
                      }
                  }
          
          
                  if (selectionArray.length)
                  {
                      app.selection = selectionArray;
                  }
                  else
                  {
                      alert("No text larger than 70pt was found.");
                  }
          
          
                  //////////////////////////////////////////////////////////////////////////
                  //uncomment this block if you want to delete all of the text that is found
                  //////////////////////////////////////////////////////////////////////////
                  // for (var x = selectionArray.length - 1; x >= 0; x--)
                  // {
                  //  selectionArray[x].remove();
                  // }
              }
          }
          container();
          
          • 2. Re: Use applescript to delete text based on point size
            mandip94728536 Level 1

            I tried running what you made and I'm getting an error saying that it can't find the variable "app"

            • 3. Re: Use applescript to delete text based on point size
              williamadowling Level 4

              hmmm. that doesn't really make sense. app is a global variable in ESTK that points to the application "Illustrator". try restarting illustrator and ESTK and try again.

               

              My guess is that somewhere along the way, you (whether accidentally, or on purpose) clicked the "Reset" option in the Debug menu in ESTK. This clears out all of the variable declarations (including the necessary basic required ones like 'app'). I accidentally did this once. Restarting illustrator will fix it right up for you though.

              • 4. Re: Use applescript to delete text based on point size
                Silly-V Adobe Community Professional

                you may be using applescript to run this? Try to use do javascript and run the snippet created by williamdowling as a stand-alone .jsx file

                do javascript "Path/To/Script.jsx" - or however you set a file pointer in AS.

                • 5. Re: Use applescript to delete text based on point size
                  williamadowling Level 4

                  Silly, You so smaht. like wicked smaht.

                  • 6. Re: Use applescript to delete text based on point size
                    mandip94728536 Level 1

                    I don't understand your instructions. So far I've been opening the file window in Illustrator and going to scripts>other scripts then loading the file. I tried changing the script file to an jsx but that hasn't helped

                    • 7. Re: Use applescript to delete text based on point size
                      williamadowling Level 4

                      I see, do you have ESTK (ExtendScript Toolkit) installed? If not, I would recommend getting it. If you're a Creative Cloud subscriber you can download it straight through the Creative Cloud app.

                       

                      ESTK allows you to run, edit, step through, and debug your code while also giving you an inside peek at what's going on under the hood such as keeping track of current variable definitions as well as determining what properties and methods you have available to you. If you're going to get involved in scripting Illustrator (or Photoshop or InDesign etc) ESTK is a must have tool.

                       

                      For your purposes right now, you may be able to get away with a quick easy fix. add the following line to the very top of the script that I gave you above:

                       

                      #target Illustrator

                       

                      and then save the file as a .jsx file.

                       

                      Perhaps since there's no target defined, Illustrator is not using the correct script engine??? It's hard to say without having any knowledge of your setup.

                       

                      let us know how it goes.

                      • 8. Re: Use applescript to delete text based on point size
                        mandip94728536 Level 1

                        I'm using something called Script Editor. It has an option for apple script and java script. I set it to Java script but that's not helping. When I added #target illustrator to the top of the script, Script Editor wouldn't let me save. A pop up said there was a syntax error and that "#" is an invalid character. I tried taking off the # but then it said "Illustrator" is an unexpected identifier and still won't let me save. I tried "Adobe Illustrator" to no avail

                        • 9. Re: Use applescript to delete text based on point size
                          williamadowling Level 4

                          use TextEdit (or some other text editor) to save the file. i'm not a fan of Script Editor. It seems very specialized in my opinion, and it doesn't quite lend itself to illustrator scripting.