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

How to undo one function?

Contributor ,
May 30, 2019 May 30, 2019

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

TOPICS
Scripting

Views

322

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 ,
May 30, 2019 May 30, 2019

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

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 ,
May 30, 2019 May 30, 2019

Copy link to clipboard

Copied

LATEST

Thank you Uwe.

John

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