Skip to main content
Inspiring
December 25, 2023
Answered

[Q] Is app.redraw() the best way to force a redraw in a tight loop?

  • December 25, 2023
  • 2 replies
  • 841 views

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'?

This topic has been closed for replies.
Correct answer Sergey Osokin

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. 🙂

 

 

2 replies

Sergey Osokin
Sergey OsokinCorrect answer
Inspiring
December 26, 2023

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. 🙂

 

 

Inspiring
December 27, 2023

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");

 

m1b
Community Expert
Community Expert
December 27, 2023

Thanks for letting us know the best way you found @tomd75724979.

m1b
Community Expert
Community Expert
December 25, 2023

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