Copy link to clipboard
Copied
Still in the process of writing a script to use variable data to save out print files and have come across having to rasterize one of the variable text fields. Without using the obvious undo(); cause that doesn't work within a loop, is there a way to return to an un-rasterized state? Any ideas are welcome.
How can that make file larger if you delete it when finished?
Any way, you sure can use undo() within you for loop, simply add one line: app.redraw(), then app.undo(). Try this:
var t = activeDocument.textFrames.add();
t.contents = "welcome back!"
app.redraw();
for (var i = 1; i < 6; i++) {
t.contents = "Hello, here comes " + i;
app.redraw();
alert(t.contents);
app.undo();
alert(t.contents);
};
app.undo();
Copy link to clipboard
Copied
Can you elaborate more on the exact scenario where rasterizing is required?
Are you open to instead use the Rasterize Effect, which provides benefits of rasterizing while also retaining your base art?
Copy link to clipboard
Copied
As the variable changes the text, each text area needs to be rasterized due to complicated fills (Camo, Carbon Fill etc). Then un-rasterize to change to the next variable in line. Make sense? I am using this with the last script you had helped me with. Which I still owe you for. Thanks again.
Copy link to clipboard
Copied
Why not duplicate the text item and delete it when finish?
Copy link to clipboard
Copied
Duplicating will only make the file larger. I would rather keep the original element intact.
Copy link to clipboard
Copied
How can that make file larger if you delete it when finished?
Any way, you sure can use undo() within you for loop, simply add one line: app.redraw(), then app.undo(). Try this:
var t = activeDocument.textFrames.add();
t.contents = "welcome back!"
app.redraw();
for (var i = 1; i < 6; i++) {
t.contents = "Hello, here comes " + i;
app.redraw();
alert(t.contents);
app.undo();
alert(t.contents);
};
app.undo();
Copy link to clipboard
Copied
The text already has a repetitive fill in it, then to duplicate and rasterize another on top of it would make it a much larger file. Make sense.
Anyhoo. i will try the above to see if I can get the desired result. Thanks for the help M.
Copy link to clipboard
Copied
If i understand correctly, moluapple is suggesting that you delete the duplicate when you're done, ergo, the file size does not change.
if you have:
var art = (the vector art you want to rasterize)
var artCopy = art.duplicate();
artCopy.rasterize() // this is not the right syntax. i don't use rasterization in my workflow so i haven't learned it yet, but you get the point.
doFunctionOnRasterizedArt(param1,param2)
artCopy.remove();
This way you can do whatever function you need to do on the rasterized art, then delete it when you're finished and there's no need to unrasterize.
Copy link to clipboard
Copied
SUCCESS!! Redraw(); worked perfectly rasterizing then un-rasterizing as needed. Below is a snippet of the code for reference.
app.redraw();
for(var a=0;a<myLayer.pageItems.length;a++){
var currentItem = myLayer.pageItems;
currentItem.selected = true;
idoc.rasterize( currentItem ,currentItem.visibleBounds, newoptions);
}
docRef.saveAs(File("my.pdf"), myOpts);
app.undo();
Thank You!!