Copy link to clipboard
Copied
I'm drawing a great many path items in a tight loop. I'd like to see each one appear as soon as it has been drawn. I currently use app.redraw() for this.
Is this the best way? As I understand it, redraw() is a method of the app object and is intended to fully redraw the Illustrator UI, so all palettes and menus.
Is there anything that just redraws the 'canvas'?
One way. Replace app.redraw() with app.executeMenuCommand("artboard"). After each rectangle, toggle Hide / Show Artboards. And after the loop, add this command again. This will result in a single action being written to the document history, as opposed to app.redraw() which will create multiple entries in the history. But "artboard" will cause a flickering effect of the artboard borders in the loop and I don't recommend it for epileptics. 🙂
Copy link to clipboard
Copied
Hi @tomd75724979, as far as I know app.redraw() is the only way to do this.
By the way, it will also add a record to the undo stack each time, which is usually undesirable. So it means that after drawing 10 path items, the user would have to undo 10 times to go back. If not using app.redraw(), they would undo the entire script at once.
The redraw is also very slow, as you will have noticed. Generally we try to minimize dealings with the DOM as much as possible to avoid slow-downs.
- Mark
Copy link to clipboard
Copied
One way. Replace app.redraw() with app.executeMenuCommand("artboard"). After each rectangle, toggle Hide / Show Artboards. And after the loop, add this command again. This will result in a single action being written to the document history, as opposed to app.redraw() which will create multiple entries in the history. But "artboard" will cause a flickering effect of the artboard borders in the loop and I don't recommend it for epileptics. 🙂
Copy link to clipboard
Copied
Mark, Sergey, many thanks! Very useful tips and insights.
From my side, I can add that putting the document in fullscreen mode and in preview mode will prevent flickering with Sergey's artboard trick and also make things render faster:
app.activeDocument.views[0].screenMode = ScreenMode.FULLSCREEN;
app.executeMenuCommand("preview");
Copy link to clipboard
Copied
Thanks for letting us know the best way you found @tomd75724979.
Copy link to clipboard
Copied
With Overpint Preview, the borders of the artboard are thinner, so the flicker is less noticeable, but still present 🙂 Since I was recording GIFs, the recorder reduced the frame rate, and in my demo it may look like the flicker is delayed, but in reality it is fast.
Of course, at the end, the saved window view is returned. I'm glad you found the fullscreen trick, I've used it a few times in scripts.
var doc = app.activeDocument;
var docView = doc.views[0].screenMode;
doc.views[0].screenMode = ScreenMode.FULLSCREEN;
// .... your code
doc.views[0].screenMode = docView; // final
Copy link to clipboard
Copied
Great tip @Sergey Osokin!