Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Rasterize .pngs in document and move to specific layer

Engaged ,
Oct 03, 2014 Oct 03, 2014

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

TOPICS
Scripting
900
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Oct 03, 2014 Oct 03, 2014

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;

  thisItem.move(myLayer, ElementPlacement.PLACEATEND);

}

Translate
Adobe
Engaged ,
Oct 03, 2014 Oct 03, 2014

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, selectedItems.controlBounds,rasterizeOptions);

  }  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 03, 2014 Oct 03, 2014

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;

  thisItem.move(myLayer, ElementPlacement.PLACEATEND);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 06, 2014 Oct 06, 2014

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, selectedItems.controlBounds,rasterizeOptions);

  moveToLayer();

  }

function moveToLayer()

  {

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

  {

   var thisItem = myDoc.rasterItems;

   thisItem.move(myLayer, ElementPlacement.PLACEATEND);

  }

  }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 06, 2014 Oct 06, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 06, 2014 Oct 06, 2014

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, selectedItems.controlBounds,rasterizeOptions);

}

// move rasterized items to specified layer

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

{

var thisItem = myDoc.rasterItems;

thisItem.move(myLayer, ElementPlacement.PLACEATEND);

}

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 06, 2014 Oct 06, 2014
LATEST

This is looking good!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines