Copy link to clipboard
Copied
I ran into a problem in my script that redraw happened to fix for me, and now I have 5 or 6 redraw commands total... However, I liked how one single undo command undid the entire script, but now I have to hit undo 5 or 6 times, it's not major but just wondering if preventing this is possible.
2 Correct answers
One main function is like you mentioned, you want to show the user the document's changes before the script ends.
But sometimes when doing a lot of document manipulation where artwork gets put from various documents into other documents, the script will experience some kinds of bugs that would lead you to believe that the script is working with some 'outdated' version of where the artwork is supposed to be. That's when I stick in a redraw() and sometimes it was the solution!
redraw() also helps when applying Effects or LiveTracing. Sometimes (not always) it's necessary to redraw the screen. Problem is to tell when, Illustrator is like a wild beast we have to domesticate.
Explore related tutorials & articles
Copy link to clipboard
Copied
undo() will undo the last act. If the last act was redraw(), I don't see how it can take you before that.
Copy link to clipboard
Copied
I meant undoing after running a script... one undo after running the script would take me back before running any of the script, undoing dozens of commands all at once. But now that the script has redraw's in it, each undo only goes back to the previous redraw command.
It's minor, but I liked it when everything was being undone with just one command, as I test things the extra undo's feel excessive.
Copy link to clipboard
Copied
Gotya. Still, redraw() counts as your last act, so one undo() will undo that but no further.
Copy link to clipboard
Copied
Hmm! Not sure I understand your question, but would it help if the the Script put the View into Outline before runnng?
There's no redrawing when all you see is vector outlines on your screen.
Copy link to clipboard
Copied
Hmmm, that might help. Is switching the preview a common tactic for helping with performance of scripts, it seems like it might a good strategy, just in general for scripts that do a lot of work.
And just to explain the original question better, say I have a script that creates 10 rectangles. After the script finishes, pressing undo just one single time undoes all 10 rectangles at once. But if the script creates 5 rectangles, then does a redraw(); and then creates another 5 rectangles, after it finishes, pressing undo one time no longer undoes everything, it just undoes the last 5 rectangles.
It's minor, but I like the outline idea.
Copy link to clipboard
Copied
Not sure, I'm not a scripter. But I found another post about it that's active right now: https://community.adobe.com/t5/illustrator/suspend-ui-during-script-execution/td-p/11362997?page=1
See the post from CarlosCanto.
Copy link to clipboard
Copied
I don't have an answer, but I'm curious: what do the redraw() commands fix? I've mainly used them to either update the UI or to provide intermediate levels of undo.
Copy link to clipboard
Copied
One main function is like you mentioned, you want to show the user the document's changes before the script ends.
But sometimes when doing a lot of document manipulation where artwork gets put from various documents into other documents, the script will experience some kinds of bugs that would lead you to believe that the script is working with some 'outdated' version of where the artwork is supposed to be. That's when I stick in a redraw() and sometimes it was the solution!
Copy link to clipboard
Copied
Ah! Thanks.
Copy link to clipboard
Copied
redraw() also helps when applying Effects or LiveTracing. Sometimes (not always) it's necessary to redraw the screen. Problem is to tell when, Illustrator is like a wild beast we have to domesticate.

