13 Replies Latest reply on Jul 26, 2012 10:11 AM by Marijan Tompa [tomaxxi]

    Undo Event

    Shadowfax Level 1

      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.

        • 1. Re: Undo Event
          Peter Kahrel Adobe Community Professional & MVP

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

           

          What do you do to undo?

           

          Peter

          • 2. Re: Undo Event
            Shadowfax Level 1

            Thanks for your reply.

             

            Actually this is what my script does:

             

            1. I have a palette that has many iconbuttons in it. When i select a frame in the document, and click on an iconbutton (in the palette) , that image corresponding to that iconbutton  is placed in that frame and status(statictext) is set as "Flown" inside the palette.

             

            2. When i delete the image or the frame containing the image, the status of that image inside the palette is set as "not flown". For detecting this deletion event, i have used "afterSelectionChanged".

             

            Now, the problem is, when i press Ctrl+Z(Undo) immediately after placing an image(currentSelection.place), i am not able to change the status in my palette, since the selection is not changed with undo( because afterSelectionChanged event is not triggered).

             

            So, what can i do to detect undo in such a scenario.

            • 3. Re: Undo Event
              Cenchen Level 2

              Try this,

               

              if(app.activeDocument.modified == true)

              {

              do{

                  try{

                      app.activeDocument.undo()

                      }

                  catch(e){exit()}

                   }

                   while(app.activeDocument.modified == true)

              }

              alert("Completed...")

              • 4. Re: Undo Event
                Shadowfax Level 1

                but modify need not be just UNDO, it can be any thing..

                • 5. Re: Undo Event
                  Cenchen Level 2

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

                  • 6. Re: Undo Event
                    Cenchen Level 2

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

                    • 7. Re: Undo Event
                      Marijan Tompa [tomaxxi] Level 4

                      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

                      • 8. Re: Undo Event
                        Marijan Tompa [tomaxxi] Level 4

                        @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)

                        • 9. Re: Undo Event
                          Cenchen Level 2

                          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)

                          • 10. Re: Undo Event
                            Harbs. Level 6

                            Eyenan,

                             

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

                            • 11. Re: Undo Event
                              Shadowfax Level 1

                              thanks a lot Marijan.

                               

                              Is there any id/name exist for "REDO" also ?

                              • 12. Re: Undo Event
                                Shadowfax Level 1

                                for redo its :266... thanks a ton Marijan.. you saved my day

                                • 13. Re: Undo Event
                                  Marijan Tompa [tomaxxi] Level 4

                                  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)

                                  1 person found this helpful