Copy link to clipboard
Copied
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');
Hi,
So as per the contract of the doScript method, the first argument can be a File, String or a JavascriptFunction. See the details at
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html#d1e42173__d1e45616
Now lets take your first use case
app.doScript(String(main()),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
In the above you have called the method main by using the statement main(), so it will be called and the return value of it would be pass
...Copy link to clipboard
Copied
Hi,
So as per the contract of the doScript method, the first argument can be a File, String or a JavascriptFunction. See the details at
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Application.html#d1e42173__d1e45616
Now lets take your first use case
app.doScript(String(main()),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
In the above you have called the method main by using the statement main(), so it will be called and the return value of it would be passed to the String constructor and the resulting value is then used to call the doScript method. Seems your method does not return anything in which case it would be undefined and the above call would be equivalent to the following when the doScript method is called
app.doScript(String(undefined),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
The String(undefined) would return a string undefined and thus no code was actually called by doScript and hence you don't see any undo entry in the Edit menu
Now in your second use case
app.doScript(main(),ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
The main method is called and its return type is then used to call the doScript method. This is equivalent to the following when the doScript method is called
app.doScript(undefined,ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
Thus the error that pops up makes sense.
Correct way of calling the doScript method. We generally just use the method name without the invocation braces. So the following should work good
app.doScript(main,ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
If we need to pass the arguments, we can also use the string form as follows
app.doScript("main()",ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
Hope this clears out your confusions.
-Manan
Copy link to clipboard
Copied
Thank you Manan 🙂
Your detailed explanation is very helpful. Thank you !
m.
Copy link to clipboard
Copied
Would you please explain me in details what is the difference between UndoModes ?
Thank you in advance 🙂
m.
Copy link to clipboard
Copied
The difference between Undo modes is in the documentation, is any part of it unclear?
What does your updated script line look like now you have corrected the incorrect function call?
Copy link to clipboard
Copied
Thank you for answer.
I can't see any diference betwen ENTIRE_SCRIPT and FAST_ENTIRE_SCRIPT. Is the speed diference visible only in case of undoing very complex functions or scripts ? or the diference manifests itself in other way?
Now, my well working line of code looks like that :
app.doScript(main,ScriptLanguage.JAVASCRIPT,[],UndoModes.ENTIRE_SCRIPT,'main');
Best regards
m.
Copy link to clipboard
Copied
Hi,
There is not much explanation on the undo modes that i could find the last time i checked. Based on my experience the safest mode that i have found out has been the entireScript. Fast mode should give a speed boost in case of complex operations, but it requires some thought before being used, i never got into a situation to actually investigate using it personally. Marc has written a blog highlighting the use cases and his observations regarding the undo modes that you can look into and then start experimenting yourself
http://www.indiscripts.com/post/2011/08/notes-on-fastentirescript-undo-mode
-Manan
Copy link to clipboard
Copied
Hi Manan, thank you again for pointing me on Marc's article. As always Mark dive deeply into a subject .... but this time his eplanations were understandable in full for me... 🙂
Best regards
m.