Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

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

Explorer ,
Dec 25, 2023 Dec 25, 2023

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

TOPICS
Scripting
481
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Dec 25, 2023 Dec 25, 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. 🙂

2023-12-26 10.12.50.gif

 

 

Translate
Adobe
Community Expert ,
Dec 25, 2023 Dec 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 25, 2023 Dec 25, 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. 🙂

2023-12-26 10.12.50.gif

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 27, 2023 Dec 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");

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 27, 2023 Dec 27, 2023

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 27, 2023 Dec 27, 2023
LATEST

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

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 27, 2023 Dec 27, 2023

Great tip @Sergey Osokin!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines