Copy link to clipboard
Copied
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
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);
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
This is looking good!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now