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

Turn Off/Limit Undos

Community Beginner ,
Jul 26, 2023 Jul 26, 2023

I am automating a job in Indesign (500+ pages) using javascript. I've got the script to work, but it slows down to a crawl the longer it runs. I suspect that because Indesign's undos are limited only by the sytem's ram, that is what is causing the slow down in the script. Is there a way to turn off or limit the number of undos? 

TOPICS
Scripting
311
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
People's Champ ,
Jul 26, 2023 Jul 26, 2023

You can only script what's feasible in the UI (the other way around not always true). 

But in that case, no, you cannot.

That said, it's a weird conclusion to me that undo levels would affect your script performance. There are zillions reasons others than this one that could be investigated. 

An easy way to figure is to run your script in a whole cancelable sequence (only one undo here)

var u;

app.doScript("myScript(…)",u,u,UndoModes.ENTIRE_SCRIPT, "One undo");

That would discard the undo concern. 

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 ,
Jul 26, 2023 Jul 26, 2023

I, too, doubt that accumulated undo levels is affecting your script's performance. But there is a way to purge undos. Do a Save As. THis creates a new file and removes the undo history of the file. Try it with a text document. Add a Save As step in your script where you are detecting the performance lag. See if that improves things.

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 ,
Jul 26, 2023 Jul 26, 2023

Hi @gnuklear , Can you post your code or describe what you are repeating in your loop(s)? It doesn’t seem likely that history itself would be a problem. This example duplicates a rectangle 1000 times and takes a few sec to run on my 2019 iMac:

 

app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
var doc = app.documents.add();
var r = doc.pages[0].rectangles.add();

for (var i = 0; i < 1000; i++){
    r.duplicate( [ i*.5 , i*.5 ]); 
};  
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 ,
Jul 26, 2023 Jul 26, 2023

And if I run the loop in a doScript() as @Loic.Aigon suggests the execute time is the same—3-4 secs:

 

//Undo Command 
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Dupe Rectangle');

function main(){
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
    var doc = app.documents.add();
    var r = doc.pages[0].rectangles.add();
    
    for (var i = 0; i < 1000; i++){
        r.duplicate( [ i*.5 , i*.5 ]); 
    };   
}

 

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
LEGEND ,
Jul 26, 2023 Jul 26, 2023
LATEST

Yes, Undo can slow you down. But Undo history is not limited by the amount of RAM - it can only be limited by free space on your drive - it's constantly added to your INDD file - that's why INDD file can get so big over time - if there is no Save As with a new name. 

 

As already mentioned - you can't completely turn it off - but as per @Scott Falkner suggestion - you can purge it by doing Save As with a new name.

 

Extra benefit - you get backup / point that you can continue from in case your script crashes.

 

You can speed up your script / process - if you open / create your document as hidden - without the window - as InDesign doesn't have to refresh the preview - you should get about 30% boost.

 

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