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);
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.
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.
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
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.
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
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
Copy link to clipboard
Copied
You're definitely right. Thanks for spotting that I don't usually use two for loops in the same scope