11 Replies Latest reply on Aug 28, 2017 12:10 AM by CarlosCanto

    Undo does not work with bridge talk

    taniwaki yuya Level 1

      With script ui, by clicking the button.


      I use bridge talk to run the script
      I want to use the undo function in exception handling when an error occurs
      I think that it is not working.

       

      Does it not work within bridge talk?

       

      I think whether to consider the whole processing at bridge talk as one operation
      I tried undo in onclick after an error was returned
      An error occurred without an app object.

       

      Whichever method is impossible?

       

       clCreateBtn.onClick = function(){
      
        var bt = new BridgeTalk();
        bt.target = "Illustrator";
        bt.body = uneval(illustratorCreateLayer) + "(" + args+ ")";
        
        bt.onResult = function(res) {
         var result = eval(res.body);
         if(result == "1"){
          alert("error");
          undo();          // app error no object!!!
          return;
         }
         alert("ok");
        }
        bt.send();
       }
      
       function illustratorCreateLayer(){
        
        var doc = activeDocument;
        try{
           // etc process
        }catch(e){
         undo();           // not working!!!
         return "1";
        }
        return "0";
       }
      

       

      line at 11or25.

      Please tell me if there is a solution.

      Best regard.

        • 1. Re: Undo does not work with bridge talk
          Ten A Adobe Community Professional

          undo method is under the application class. Try below.

           

          app.undo();
          
          • 2. Re: Undo does not work with bridge talk
            taniwaki yuya Level 1

            Hi Ten A.

            thank you for your answer.


            However, reference from app does not work either.
            Strictly speaking, it does not mean that an error occurs, it seems that nothing happens.

            My prediction is that once the script finishes from the beginning to the end it is counted as one action on illlustarot,
            Since it is assumed that from operation of path to catch until undo is one action
            I think that nothing will happen because it is judged that there is nothing to undo yet.

            • 3. Re: Undo does not work with bridge talk
              Ten A Adobe Community Professional

              I'm not shure what you want to do with that. However, If you think to do something with ScriptsUI's parette, I recommend to move it to CEP extension.

              • 4. Re: Undo does not work with bridge talk
                taniwaki yuya Level 1

                thank you for your answer.

                 

                I am using a script UI to create a script that automatically adds a fixed layer matching the selected list
                However, a bug in the illustrator, "1346458189 ('PARM')" occasionally occurs.
                Please see below for bugs.
                Https://forums.adobe.com/thread/748031

                 

                So, if this unreasonable bug occurs, I would like to undo it here.
                If this bug does not occur in the first place, it is a matter which I do not mind ...

                 

                I do not know, but what is CEP extension?
                Best Regard.

                • 6. Re: Undo does not work with bridge talk
                  taniwaki yuya Level 1

                  It was a Japanese, I am also.
                  The Japanese forum is not very active, so I was asking questions on this forum.
                  While translating with google ...

                  Your article has been referred to when I was looking elsewhere.
                  I will refer to this article as well.
                  Thank you very much.

                  • 7. Re: Undo does not work with bridge talk
                    CarlosCanto Adobe Community Professional & MVP

                    app.undo() does work. Your code works as well.

                     

                    try this snippet, undo and redo buttons are dedicated BT functions. Test button is where your code is, I added accessing a layer that does not exist to generate an error, then it will call app.undo()

                     

                    // test undo/redo, Carlos Canto
                    // https://forums.adobe.com/thread/2368801
                    
                    
                    #targetengine main
                    
                    
                    var win = new Window("palette","Test Undo/Redo");
                    var grpUndoRedo = win.add("group");  
                    var btnUndo = grpUndoRedo.add("button", undefined, "U");
                    var btnRedo = grpUndoRedo.add("button", undefined, "R");
                    
                    
                    var grpBtns = win.add("group");  
                    var btnCopy = grpBtns.add("button", undefined, "Test");
                    var btnPaste = grpBtns.add("button", undefined, "Paste");
                    
                    
                    btnCopy.size = btnPaste.size = [50,21];
                    btnUndo.size = btnRedo.size = [20,20];
                    
                        btnUndo.onClick = function() {
                            
                            var bt3 = new BridgeTalk;
                    
                    
                            bt3.target = "illustrator";
                            var msg3 = "\n" +
                            "app.undo();\n" +
                            "app.refresh();\n"
                    
                    
                            bt3.body = msg3;
                            bt3.send(); 
                        }
                    //---------------------------------------------------------------------------------------------------------------------------------------------------
                        btnRedo.onClick = function() {
                            
                            var bt4 = new BridgeTalk;
                    
                    
                            bt4.target = "illustrator";
                            var msg4 = "\n" +
                            "app.redo();\n" +
                            "app.refresh();\n"
                    
                    
                            bt4.body = msg4;
                            bt4.send(); 
                        }
                    //---------------------------------------------------------------------------------------------------------------------------------------------------
                        btnCopy.onClick = function() {
                            args = 0;
                            //alert("Copy");
                           
                            var bt5 = new BridgeTalk;
                    
                    
                            bt5.target = "illustrator";
                    
                    
                            bt5.body = uneval(illustratorCreateLayer) + "(" + args+ ")";
                            bt5.send();
                        }
                    //---------------------------------------------------------------------------------------------------------------------------------------------------
                        btnPaste.onClick = function() {
                            alert("paste");
                        }
                    //----------------------------------------------------------------------------------------------------------------------------------------------
                        win.center();
                        win.show();
                       
                    function illustratorCreateLayer(){ 
                       
                          var doc = activeDocument; 
                          try{ 
                            var ilayer = doc.layers['cut'];
                          }catch(e){ 
                              $.writeln(e);
                          app.undo();
                          return "1"; 
                          } 
                          return "0"; 
                    }
                    
                    1 person found this helpful
                    • 8. Re: Undo does not work with bridge talk
                      taniwaki yuya Level 1

                      CarlosCanto, Thank you for your reply.

                       

                      I tried working on your script.
                      Certainly the undo, redo function itself is working properly.

                       

                      Maybe my sample code or recognition is incorrect
                      For example, in the case of the following code.

                       

                       try{   
                        var lot = doc.layers['layer1'].textFrames[0]; /* Layer 1 is a prerequisite that exist */
                        var pos = [2, 5];
                        lot.position = pos;
                        var ilayer = doc.layers['cut'];  
                       }catch(e){   
                        $.writeln(e);  
                        app.undo();  
                        return "1";   
                       }  
                      

                       

                      After pos is set and the position is changed, it is caught at the location of the 'cut' layer
                      The value set with pos is not undoed.

                      In the click event, bridetalk "illustratorCreateLayer"
                      After that, depending on the return value
                      Do you mean to do bridgetalk with only "undo"?
                      Can I restore it unless I bridge talk twice?

                       

                      best regard.

                      • 9. Re: Undo does not work with bridge talk
                        CarlosCanto Adobe Community Professional & MVP

                        Hi taniwaki, add redraw() after re positioning your text

                         

                              lot.position = pos;

                              app.redraw();

                        1 person found this helpful
                        • 10. Re: Undo does not work with bridge talk
                          taniwaki yuya Level 1

                          Hi Carlos Canto.

                           

                          If you did "redraw" it was settled ...
                          I did not understand simple things.
                          For the time being, it seems to be possible to avoid an unknown error.

                           

                          Thank you very much for your help.
                          I am grateful.

                          • 11. Re: Undo does not work with bridge talk
                            CarlosCanto Adobe Community Professional & MVP

                            you're welcome, glad it worked.

                             

                            You'll get the hang of it. BridgeTalk is the most complicated subject in my opinion. Well, xmp is complicated too as well