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

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

Explorer ,
Dec 25, 2023 Dec 25, 2023

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

TOPICS
Scripting

Views

186

Translate

Translate

Report

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

 

 

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 25, 2023 Dec 25, 2023

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

Votes

Translate

Translate

Report

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

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

2023-12-26 10.12.50.gif

 

 

Votes

Translate

Translate

Report

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

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Great tip @Sergey Osokin!

Votes

Translate

Translate

Report

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