call values outside the loop in scripting

Explorer ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

Hi everyone,

I have developed a script to display the undo history actions in seprate alert.

Inside the for loop the alert is working good.

But, outside the loop it displays only the last action of undo history in alert.

how do i get the same result outside the loop????

I have attached the sample code below

var undo = app.activeDocument.undoHistory;
for (var i = undo.length-1; i>=0; i--)
{
var result= undo[i];
alert(result);   //displays all the actions one by one in seprate alert
}
alert(result);   //displays only the last action

 

Thanks in advance....

 

Regards,

-Jothi

TOPICS
Scripting

Views

132

Likes

translate

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

Adobe Community Professional , Jul 22, 2020 Jul 22, 2020
This has nothing to do with InDesign scripting, as suggested to you on multiple occassions before, it would serve you better if you start learn basics of programming.   -Manan

Likes

translate

Translate

Translate
Adobe Community Professional ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

Hi,

Script is running correctly. First your loop is running and it is storing last value of undo[i] in result. Therefore, outside the loop it will alert value of undo[i]. You cannot get the result outside the for loop. UndoHistory is a set of multiple history and to get multiple history you need to do processing inside the loop only. So your script is running correctly. What exactly you want to do.? But getting same result outside the loop is possible as 

 

 

app.activeDocument.undoHistory[0]
app.activeDocument.undoHistory[1]
app.activeDocument.undoHistory[2]
app.activeDocument.undoHistory[3]

 

 

But you don't know when to stop, it may possible you write as alert(app.activeDocument.undoHistory[4]), and app.activeDocument.undoHistory[4] does not exists so it will alert undefined.

Best regards

Likes

translate

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
Adobe Community Professional ,
Jul 22, 2020 Jul 22, 2020

Copy link to clipboard

Copied

This has nothing to do with InDesign scripting, as suggested to you on multiple occassions before, it would serve you better if you start learn basics of programming.

 

-Manan

Likes

translate

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 ,
Oct 25, 2020 Oct 25, 2020

Copy link to clipboard

Copied

Hi Manan,

 

Sorry! for the late reply. I'm done with my work and there are always a way out.

 

Thanks,

Jothi

Likes

translate

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