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

Track changes report

Engaged ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Hi guys,

I'm trying to get a list of all the changes I make in the document.

It works on a small one page document with a couple of stories.

When I try it on a large document it takes so long! It's never actually finished, it just keeps running and the console always says that i=1.

Any ideas as to why or how I can speed it up?

var doc = app.activeDocument,
myStories = doc.stories.everyItem().getElements(),
myChanges;
var changes = [];

// set userName

if ( app.userName == "Unknown User Name" ) {
   
    var name = prompt( "What's your name?" );
    app.userName = name;
   
    }

// turn on track changes

   

for ( var i = 0; i < myStories.length; i++ ) {
   
   
        if ( myStories.trackChanges === false ) {
       
            myStories.trackChanges = true;
        }
   
    var story = myStories;
    myChanges = story.changes.everyItem().getElements();
   
   
        if ( myChanges  !== 0 ) {
       
            for ( var i = 0; i < myChanges.length; i++ ) {
           
            changes.push( myChanges.date + '\n' +
            myChanges.userName + '\n' +
            myChanges.changeType + ': ' + myChanges.lines[0].contents + myChanges.texts[0].contents );
           
            }
       
        }
   
}

$.writeln(changes);

TOPICS
Scripting

Views

426

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

People's Champ , Mar 14, 2017 Mar 14, 2017

Have you noticed that you are actually redifining your counter variable in the inside loop

for ( i…

     for ( i…

Use another variable such as "j" or call a function that will use a "i" counter in its own scope.

Votes

Translate

Translate
People's Champ ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Have you noticed that you are actually redifining your counter variable in the inside loop

for ( i…

     for ( i…

Use another variable such as "j" or call a function that will use a "i" counter in its own scope.

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
Engaged ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Ah! Thanks Loic

I thought that if you used var it got its own space in memory and therefore was treated as different...

Now you've fixed that problem... Do you know why my changeType property returns a number?

I get something like: 1799974515

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 ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

That's because you precede and follow it with +

One possibility to get the enumeration's text representation is to use String(myChanges.changeType) instead of myChanges.changeType.

P.

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
Engaged ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

Thanks Peter!

For some reason using the String() method caused an error. I got "undefined is not an object" on line 30.

I used myChanges.changeType.toString() and it worked perfectly

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
People's Champ ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

I thought that if you used var it got its own space in memory and therefore was treated as different...

Unless I am wrong and given that you are in the same scope, using "var i=…" will only redeclare a same variable/value

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
Engaged ,
Mar 14, 2017 Mar 14, 2017

Copy link to clipboard

Copied

LATEST

You're definitely right. Thanks for spotting that I don't usually use two for loops in the same scope

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