app.doScript() method doesn't work properly. I don't know why?

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / app.doScript() method doesn't work properly. I don't know why?

Viewing 1 reply thread
  • Author
    Posts
    • #1230805
      Robert Ploch
      Member

      Hello,
      I’m tryingo to use a method app.doSript() to invoke my fuction main() consist of a few steps in ONE UNDO mode, in case to make it undone by one step, so I wrote such line of code:

      app.doScript(String(main()),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,’main’);

      I have two questions, I can’t answer to myself:
      1. script works fine, but there is no ONE undo in edit menu of indesign, why? what is done wrong?
      2. why the main() function is invoked corectly and the function main() does it’s work after stopping runtime, but an error occurs with blue comunicate if the line looks like this:

      app.doScript(main(),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,’main’);

      Runtime Error: Error Code# 30477: Invalid value for parameter ‘script’ of method ‘doScript’. Expected File, String or JavaScript Function, but received nothing. @ file ‘~/Desktop/ZZZ_horizontalMirror.jsx’ [line:42, col:NaN]

      many thanks in advance for help with understanding the problem
      Best regards
      Robert

    • #12343096
      Jeremy Howard
      Participant

      Hey Robert,

      While you are very close, you don’t quite have the proper syntax here.

      Where you have this line:
      app.doScript(String(main()),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,’main’);

      You should have:
      app.doScript(main, ScriptLanguage.javascript, undefined, UndoModes.entireScript, “main”);

      To break it down:
      Part 1.) app.doScript(

      Part 2.) main,
      This is the name of your function. No need for any quotes or parenthesis here.

      Part3.) ScriptLanguage.javascript,
      Pretty much the same thing as what you have…

      Part 4.) undefined,
      This is where you enter any of your function inputs. If any exist, they must be input in the form of an array. I entered “undefined” but you could use the empty array like you did (I believe that the”doScript” method can work either way)

      Part5.) “main”);
      This can say anything at all, this is simply the label that will be displayed next to the word “Undo” if you go into your edit menu to undo the script. This could say anything. If you entered “wombats” here then your edit menu would read “Undo wombats” and that would undo your entire script.

      I hope that this all makes sense. Feel free to ask any questions that you may have!

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
>