4 Replies Latest reply on Oct 26, 2016 3:22 AM by JasonC75

    Selecting white paths and deleting via script

    JasonC75

      Hi Guys,

       

      I am pretty new to JS scripting in Illustrator CC.

       

      I currently have a script that does the following;

       

      • Loads a bitmap
      • Centers it
      • Performs a B/W image trace
      • 'Expands' the trace
      • and then saves the file as an AI file

       

      This is working great. But I am wondering how I could add a step after the 'Expand' to select the white content and delete it. Leaving just the black area.

       

      Any advice would be greatly appreciated.

       

      Thanks in advance

       

      Edited title to fit more with AI terminology

        • 1. Re: Selecting white paths and deleting via script
          JasonC75 Level 1

          I think I am pretty close.

           

          var itemsLength=app.activeDocument.pathItems.length;
          for(var i=0;i<itemsLength;i++)
          {
           var pathColor=app.activeDocument.pathItems[i].fillColor;
           alert(pathColor);
          
           // PSUEDO CODE
           // If path is 'white'
           // {
           //   pathItem.remove();
           // }
          }
          

           

          I can tell that there are five paths in my test file, which the script reports happily. But when I iterate through the paths they all report as being "[Gray Color]". But, the paths are either solid black or solid white.

           

          Any advice would be much appreciated

          • 2. Re: Selecting white paths and deleting via script
            pixxxel schubser Level 5

            Hmm.

            Do you really need a script?

             

            You know the "Ignore White"-option in the trace dialog?

            • 3. Re: Selecting white paths and deleting via script
              JasonC75 Level 1

              Hi there. I most certainly do

               

              I need to strip out the white paths in approximately 7000 traced files.

               

              [edit]

              Actually, I think I know what you are getting at.

               

              I just adjusted the preset to ignore white and the script now works perfectly!

               

              Thanks heaps! You are a gem

               

              (Although, it would still be nice to know why all of the paths return [GrayColor] in the script)

              • 4. Re: Selecting white paths and deleting via script
                pixxxel schubser Level 5

                You're welcome.

                 

                And the full (scripting) answer:

                With fillColor you get the color type. You can check this with replacing lin#3 and #4 in your code:

                 var Col=app.activeDocument.pathItems[i].fillColor.typename;
                 var pathColor=app.activeDocument.pathItems[i].fillColor.gray;
                 $.writeln(Col);
                 $.writeln(pathColor);
                

                 

                Furthermore:

                If you want to remove elements than you should loop backward through your document. Otherwise the removing fails.

                 

                Have fun