How to undo one function?
Copy link to clipboard
Copied
Hi experts,
How change make the script go back just one step?
my script like this:
var file = new File("C:/selection2txt.txt");
for(var i = 0; i < app.selection.length; i++) {
if (app.selection.hasOwnProperty ( "baseline" )) {
myContents = app.selection.contents;
WriteToFile(file, myContents);
}
else if (app.selection.constructor.name == "Cell") {
change();
var columnSeparatorString = '\t' ;
var rowSeparatorString = '\r' ;
var doUndo = false ;
var unmergeCell = app.menuActions.itemByName("$ID/Unmerge Cell");
if( unmergeCell.enabled ){ unmergeCell.invoke(), doUndo = true };
var cellSpan = app.selection[0].columns.length;
var text = app.selection[0].cells.everyItem().contents;
var result = [] ;
while (text.length)
{
result.push(text.splice(0, cellSpan).join( columnSeparatorString ));
};
result = result.join( rowSeparatorString );
if( doUndo ){ app.documents[0].undo() };
WriteToFile(file, result);
}
else exit ();
}function change() {
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "([^~K(「」):;『』〔〕《》〈〉]) *[\\n\\r]";
app.changeGrepPreferences.changeTo = "$1 ";
app.selection[0].changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "[\\n\\r]";
app.changeGrepPreferences.changeTo = "";
app.selection[0].changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = " +";
app.changeGrepPreferences.changeTo = " ";
app.selection[0].changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
}function WriteToFile(file, text)
{
file.encoding = "UTF-8";
file.open("w");
file.write(text);
file.close();
}// undo change(); function
How can I undo the function change(); after the selection is written to file?
thanks
regard
John
Copy link to clipboard
Copied
Hi John,
you may found the solution here:
Re: How to define undo.isValid?
Another approach would be:
1. Save the document before doing anything.
2. Change and write out all the data to files.
3. Close the document without saving.
4. Open the document again.
Regards,
Uwe
Copy link to clipboard
Copied
Thank you Uwe.
John

