Sg2.9
Problems with Item.rasterize
Recent RSS
Problems with Item.rasterize
From:  Beau
Date:  14. November 2011, 06:56

Hi - I just started working with SG, have experience with AI Javascript. This script:

// rasterize selected items

main();

function main()
{
var items = document.getItems({
selected: true
});

if( !items.length ) {
Dialog.alert( "Please art items to be rasterized" );
return;
}

var raster_layer = new Layer();
raster_layer.name = "raster";
raster_layer.activate();

var raster = Item.rasterize( items, 'rgb', 72, 0 );
}

Yields:

Can't find method com.scriptographer.ai.Item.rasterize(com.scriptographer.ai.ItemList,string,number,number).
at Scriptographer Scripts/rasterize-1.js:21
at Scriptographer Scripts/rasterize-1.js:3

Running on current mac Lion.

Aloha - Beau.

Re: Problems with Item.rasterize
From:  Beau
Date:  14. November 2011, 13:20

I reworked the script and now it works:

// rasterize selected items

main();

function main()
{
// get all selected items
var items = document.getItems({
selected: true
});

if( !items.length ) {
Dialog.alert( "Please select art item(s) to be rasterized" );
return;
}

// create a new layer to hold rasterized items
var raster_layer = new Layer();
raster_layer.name = "raster";
raster_layer.activate();

// copy all selected items to new layer
// (traversed on reverse to preserve item order)
for( var i = items.length - 1; i >= 0; i-- ) {
items[i].copyTo( raster_layer );
}

// group and rasterize
var group = Group( raster_layer.children );
var raster = group.rasterize( 'rgb', 72, 0 );

// remove group of selected items so the raster layer only contains the image
group.remove();
}

Not really sure why the static function Item.rasterize didn't work in my first attempt.

Aloha - Beau.

Scripts
08.08.14, 15:24
15.05.14, 14:23
02.03.14, 19:16
18.11.13, 14:48
22.03.13, 03:05
22.02.13, 15:45
Posts
10.01.17, 16:37
19.02.16, 06:03
19.02.16, 06:00
17.01.16, 11:00
12.01.16, 13:10
25.11.15, 08:19
Script of the Moment
Crumpler 23.07.10