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

call values outside the loop in scripting

Contributor ,
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

266

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 2 Correct answers

Community Expert , 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

Votes

Translate

Translate
Contributor , Oct 25, 2020 Oct 25, 2020

Hi Manan,

 

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

 

Thanks,

Jothi

Votes

Translate

Translate
Community Expert ,
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

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 ,
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

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

Copy link to clipboard

Copied

LATEST

Hi Manan,

 

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

 

Thanks,

Jothi

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