Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Add undo to your script revisited

Return to Member Forum

  • Author
    Posts
    • #117194

      Hi all!
      I must to revive this post cause I can’t make work this undo way, and the post it’s so old that I think that nobody will see my help request there.
      https://creativepro.com/add-undo-to-your-script.php
      I have a indesign CC 2019 script with almost 100 actions, and an “one undo to rule them all” is a great gift. I have written it right, indeed I have copied-pasted from Jongware example shown in this forum, and from another one in Adobe forums. The script works like before to add this piece of code, but app undo only shows and undoes individual steps.
      Any help to do it work?
      Thanks in advance, and sorry for my English.

    • #117230

      I am not aware of any changes in the Undo functionality, but then again, maybe you found a bug.

      There “should” not be a limit to the number of actions, but — well, maybe there is some kind of limit after all. Can you test if Undo works as expected with a smaller script? Or with less than your 100 actions?

    • #117235

      Wow! Jongware in person!!
      The first thing I would like is to thank you for help all us to create better scripts for indesign.
      And by the way, I have also signed your feature request so that indesign can be programmed in python ;) (but with my web alias)
      Here’s the web, if someone else more wish to sign:
      https://indesign.uservoice.com/forums/601021-adobe-indesign-feature-requests/suggestions/32193772-add-python-to-the-list-of-supported-scripting-lang
      Talking again about this particular case, I will try before dinner to incorporate this function into other shorter scripts.
      I will inform you as soon as I have done the tests.
      Thank you a lot for your help, Theunis.

      I’m curious, do you use the Adobe ExtendScript Toolkit to write the scripts or some other editor?
      I use Notepad++ lately because this Adobe app seems terribly limited and limiting to me…

    • #117238

      Well, I just tested the code in a 120 line script that creates numbered tab separators.
      After executing it, the UNDO menu displays the text that I have specified in app.doScript() and undoes all the steps (create the pages, add text boxes, insert the numbers and apply the indicated paragraph style) at one time.

      With another shorter script, only 5 lines for convert all variable texts into normal texts and NO UNDO trick, Undo app menu undoes 6 changes at one time, not one by one.

      Maybe the other script is too complex for this feature (it have 600 lines and growing, a palette window with about 15 buttons, 33 functions …), or maybe I’m doing it wrong?

    • #117240

      Hi José!

      Thanks for your support for Python! I don’t have many opportunities to use it, but every time I do, I think “oh but this is much easier than ExtendScript :) I indeed stay away from the ESTK as far as possible .. At work – Windows – I use TextPad, at home – Mac – I really like the ol’ TextWrangler (nearing its end-of-life support, alas). On both systems I also use Sublime Text, which – you might be interested in this! – natively can run Python!

      As for your problem … hm. I did not think there was any limit, but then again I might be mistaken and you just ran into it. You can try to minimize the number of Undo’s by wrapping only some of your functions inside an Undo. The Undo does not really *have* to be all around the entire script, it can be used for any single function as well.

    • #117242

      Thanks!
      I think like you, Python is easy but powerful!!! At first glance, i thinked “No semicolons? No brackets? Indents do all the job??? Kidding me??” But I try it, try a bit more, try one more time and… “S..t, that works really fine!!”. I hope Adobe keep in mind your (our) request.
      I’ll take a look to Textpad (very spartan!) and Sublime Text (edit all appearances of a variable name at once its a feature that I’m looking for in all editors I try). I have used Text Wrangler very few times at home (trying to find some data in hex files, years ago). Now I’m using Notepad++ and Geany (it runs Python natively too in a system console) at work, plus PyCharm Community Edition 2018 (very powerful, but a bit tricky to make python run -for me-) at home.

      Back to my undo problem: only one function do the big stuff, and it’s called in a way like that:
      if (case 1)
      call_funct(list_of_parameters_1)
      else if (case 2)
      call_funct(list_of_parameters_2)
      else
      call_funct(list_of_parameters_3)
      end if
      I’m thinking about something like that:
      if (case 1)
      app.doScript(call_funct(list_of_parameters_1), ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “My Undo”);
      else if (case 2)
      app.doScript(call_funct(list_of_parameters_2), ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, “My Undo”);
      and so on, but I dont know if I can put params there, and I havent time today to try it. It’s possible to use app.doScript in this way?

    • #117271

      Well, I have time to do more tests, and, how I can see in your web (https://jongware.mit.edu/idcs6js/pc_Application.html#doScript), I must put all params into an array, so the line will be something like that:
      app.doScript(call_funct, ScriptLanguage.JAVASCRIPT, array_of_params, UndoModes.ENTIRE_SCRIPT, “My Undo”);
      The undefined word makes reference to params.
      Ill try now.
      News ASAP.

    • #117289

      It’s alive!
      It works! The big problem was that the params array can’t have any object, only scalar types.
      Theunis, I wish to make you a suggestion, in your web that array is explained in this way:

      any doScript (script: varies[, language: ScriptLanguage=ScriptLanguage.UNKNOWN][, withArguments: Array of any][, undoMode: UndoModes=UndoModes.SCRIPT_REQUEST][, undoName: string=Script])

      withArguments Array of any An array of arguments passed to the script. (Optional)

      I think that must be changed.
      I’m looking for the web where I found that explanation, I just was stacked because the params seems not to arrive to the function until I changed the objects for numbers, and… it worked. But I have it in the other computer. I’ll change and paste here.
      Again, thanks a lot Theunis!

    • #117290

      Here`s the link to the explain of the params that app.doScript accept.

      https://kasyan.ho.com.ua/tips/indesign_script/all/do_script.html

      The only thing I can say is that everything Kasyan demostrates there it`s fulfilled in my script.

    • #117311

      Oh that is a nice catch! I’ve only used the most basic form of parameters, nothing really fancy, and this is really something to keep in mind. Kasyan’s summary is extremely helpful, describing this problem (oversight? bug?).

      Well done on going all the way pursuing a solution!

    • #117312

      Thanks!
      But If I had not found this website, I would have abandoned the idea of using UNDO in my script.
      In any case, I must give thanks to both, you and him, for sharing information with all of us.
      I only hope this post can help more people to do better scripts. I’ll be happy if it happens!
      It has been a pleasure to meet you “in person” ;)
      Until next time, mate!

    • #14323958

      How to change the functionalities of SDK and UI to develop a new plug-in from the existing plug-ins..???

      And please help me with JavaScript code for undo and redo history for multiple times.

Viewing 11 reply threads
  • You must be logged in to reply to this topic.
Forum Ads