Skip navigation
Currently Being Moderated

Undo Event

Jul 26, 2012 12:37 AM

How can we get the UNDO event in our script? Actually my script takes the effect of the image/frame selection/desection, but with undo i don't get any selection and the result is not correct.

 

so, if i can get the undo event that problem can be hanled.

 
Replies
  • Currently Being Moderated
    Jul 26, 2012 12:57 AM   in reply to sahil.dillinger

    > with undo i don't get any . . .

     

    What do you do to undo?

     

    Peter

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 3:03 AM   in reply to sahil.dillinger

    Try this,

     

    if(app.activeDocument.modified == true)

    {

    do{

        try{

            app.activeDocument.undo()

            }

        catch(e){exit()}

         }

         while(app.activeDocument.modified == true)

    }

    alert("Completed...")

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 4:05 AM   in reply to sahil.dillinger

    okay, you can use only try...catch.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 4:08 AM   in reply to Cenchen

    It will undo only once...but if you put modify then it will undo everything...

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 4:11 AM   in reply to sahil.dillinger

    You could attach event listener to the Undo menu action.

     

    Example:

    #targetengine "tomaxxiTEST"
     
    ( function () {
        
        main ();
        
        function main () {
            var
                beforeUndo = app.menuActions.itemByID ( 265 ).addEventListener ( "beforeInvoke", eventHandler ), // UNDO
                afterUndo = app.menuActions.itemByID ( 265 ).addEventListener ( "afterInvoke", eventHandler ), // UNDO
        }
        
        function eventHandler ( evt ) {
            alert ( evt.eventType + " | " + evt.currentTarget.name );
        }
     
    } ) ();
    

     

    Hope that helps.

     

    --

    Marijan (tomaxxi)

    http://tomaxxi.com

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 4:14 AM   in reply to Cenchen

    @EyenanC:

     

    I don't understand the meaning of your function.

    Do...while doesn't makes sense here.

     

    Why can't you do it like this:

     

    if( app.activeDocument.modified == true )
        app.activeDocument.revert ();
    

     

    --

    Marijan (tomaxxi)

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 4:40 AM   in reply to Marijan Tompa

    Hi Marijan,

     

         Here discussion about "undo" not a revert. both are different.... and also we can't able to do step by step process in revert methode but we can do in an undo....

     

    do

    {

      try{

      app.activeDocument.undo()

      if(app.selection[0].constructor.name == "TextFrame")

      {

         //Process here

      }

    }

    catch(e){exit()}

    }while(app.activeDocument.modified == true)

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 5:00 AM   in reply to Cenchen

    Eyenan,

     

    I think you missed the point. Sahil is trying to catch an undo event. Not invoke undo...

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 26, 2012 10:11 AM   in reply to sahil.dillinger

    You are welcome!

     

    You can use this function to get all available menu actions with their IDs.

     

    var
        menuActions = app.menuActions,
        menuActionsLength = menuActions.length,
        menuActionsList = [],
        newDoc = app.documents.add (),
        docPage = newDoc.pages [ 0 ],
        docMargins = docPage.marginPreferences,
        actionsTextFrameBounds = [
            docPage.bounds [ 0 ] + docMargins.top,
            docPage.bounds [ 1 ] + docMargins.left,
            docPage.bounds [ 2 ] - docMargins.bottom,
            docPage.bounds [ 3 ] - docMargins.right, ],
        actionsTextFrame = newDoc.pages [ 0 ].textFrames.add ( { geometricBounds : actionsTextFrameBounds } ),
        actionsTable = actionsTextFrame.insertionPoints [ 0 ].tables.add ( { columnCount : 3, bodyRowCount : menuActionsLength } ),
        i = 0;
     
    for ( i ; i < menuActionsLength ; i++ )
        menuActionsList.push ( menuActions [ i ].name.toString () ),
        menuActionsList.push ( menuActions [ i ].area.toString () ),
        menuActionsList.push ( menuActions [ i ].id.toString () );
     
    actionsTable.contents = menuActionsList;
    

     

    --

    Marijan (tomaxxi)

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points