6 Replies Latest reply on Oct 6, 2014 12:39 PM by Silly-V

    Rasterize .pngs in document and move to specific layer

    subieguy2 Level 1

      I am wanting a javascript that will look at the active document and find any images (.png files) and rasterize each graphic to RGB 150 ppi.

      Then move the files to a layer that already exist in the document name: 1st Data

      The 1st Data layer is the bottom most layer in the document if that makes a difference.

       

      Can anyone advise as to if this is something possible to do?

       

      Any help would be greatly appreciated!

       

      Windows 7 64 bit and Illustrator CS4

        • 1. Re: Rasterize .pngs in document and move to specific layer
          subieguy2 Level 1

          I guess I should post what code I currently have..... This is the code I am using currently to strictly rasterize the selected png graphics in the document.

           

          #target illustrator

          var selectedItems = selection;

          var myDoc = app.activeDocument;

           

           

          for ( var i=0; i < selectedItems.length ; i++ )

            {

            var rasterizeOptions = new RasterizeOptions; 

            rasterizeOptions.padding = -36.25;

            rasterizeOptions.resolution = 300;

            rasterizeOptions.transparency = true;

            myDoc.rasterize(selectedItems[i], selectedItems[i].controlBounds,rasterizeOptions);

            }  

          • 2. Re: Re: Rasterize .pngs in document and move to specific layer
            Silly-V Adobe Community Professional

            Your script should find a way to move the resulted rasterItems into your layer.

             

            var myLayer = myDoc.layers.getByName('1st Data');
            for ( var i=0; i < myDoc.rasterItems.length ; i++ )
            {
              var thisItem = myDoc.rasterItems[i];
              thisItem.move(myLayer, ElementPlacement.PLACEATEND);
            } 
            
            • 3. Re: Re: Rasterize .pngs in document and move to specific layer
              subieguy2 Level 1

              That worked perfect! I made it a function and called it....THANKS!!!

              Here is the final code for anyone to reference:

               

              #target illustrator

              var selectedItems = selection;

              var myDoc = app.activeDocument;

              var myLayer = myDoc.layers.getByName('1st Data');

               

               

              for (var i=0; i<selectedItems.length; i++)

                {

                var rasterizeOptions = new RasterizeOptions; 

                rasterizeOptions.padding = 0;

                rasterizeOptions.resolution = 150;

                rasterizeOptions.transparency = true;

                myDoc.rasterize(selectedItems[i], selectedItems[i].controlBounds,rasterizeOptions);

                moveToLayer();

                }

               

               

              function moveToLayer()

                {

                for (var z=0; z < myDoc.rasterItems.length ; z++ )

                {

                 var thisItem = myDoc.rasterItems[z];

                 thisItem.move(myLayer, ElementPlacement.PLACEATEND);

                }

                }

              • 4. Re: Rasterize .pngs in document and move to specific layer
                Silly-V Adobe Community Professional

                Actually, sir, you probably want to leave it after your rasterizing loop, because the function you've made takes every raster item in the document and does the thing, even the ones already inside your 1st Data layer.  Of course, it may work for now, but it's less efficient.

                • 5. Re: Rasterize .pngs in document and move to specific layer
                  subieguy2 Level 1

                  Thank you for the feedback! I have changed it and tested it according to what you recommended. Efficiency is important...after all that is why we script right!?

                  Thanks again!!

                   

                  CORRECTED CODE BELOW:

                   

                  #target illustrator

                  var selectedItems = selection;

                  var myDoc = app.activeDocument;

                  var myLayer = myDoc.layers.getByName('Paste 1st (Data)');

                   

                  // rasterize selected items

                  for (var i=0; i<selectedItems.length; i++)

                  {

                  var rasterizeOptions = new RasterizeOptions; 

                  rasterizeOptions.padding = 0;

                  rasterizeOptions.resolution = 150;

                  rasterizeOptions.transparency = true;

                  myDoc.rasterize(selectedItems[i], selectedItems[i].controlBounds,rasterizeOptions);

                  }

                   

                  // move rasterized items to specified layer

                  for (var z=0; z < myDoc.rasterItems.length ; z++ )

                  {

                  var thisItem = myDoc.rasterItems[z];

                  thisItem.move(myLayer, ElementPlacement.PLACEATEND);

                  }

                   

                  Please let me know if you see anything else that should be corrected!