• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

doScript() method questions....

Explorer ,
Feb 28, 2020 Feb 28, 2020

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');

 

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 🙂
regards 
m.

 

 

TOPICS
Scripting

Views

3.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 29, 2020 Feb 29, 2020

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

...

Votes

Translate

Translate
Community Expert ,
Feb 29, 2020 Feb 29, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2020 Mar 01, 2020

Copy link to clipboard

Copied

Thank you Manan 🙂 

Your detailed explanation is very helpful. Thank you !

m. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2020 Mar 01, 2020

Copy link to clipboard

Copied

Would you please explain me in details what is the difference between UndoModes ?

Thank you in advance 🙂

m.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2020 Mar 01, 2020

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 01, 2020 Mar 01, 2020

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 01, 2020 Mar 01, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 03, 2020 Mar 03, 2020

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines