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

call values outside the loop in scripting

Contributor ,
Jul 22, 2020 Jul 22, 2020

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

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

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

Translate
Community Expert ,
Jul 22, 2020 Jul 22, 2020

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

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

Hi Manan,

 

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

 

Thanks,

Jothi

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