What is #targetengine?

Only my previous experience with #targetengine is that I used #targetengine "session"; to turn the dialog into a palette when writing scripts in InDesign. But when I try to understand how the script menu is, I start to see that it pops up using other methods and using the term (target?), Other than session .

Adobe loves to assume that anyone who wants a script is sometimes an experienced programmer, so I have not found a clear explanation as to what it is.

So when I use #targetengine , what do I do? Can I use any term other than "session" ? Some searches have suggested that this function is associated with global variables; what's up If so, how can I clear them without restarting InDesign? Is it a JavaScript object or an ExtendScript / InDesign function?

+8
source share
2 answers

#targetengine specific to Adobe scripts in InDesign, PhotoShop, Illustrator, etc. is not a general Javascript function.

Specifies how to handle all global β€œthings” - not only variables, but also function declarations and any other changes to the global status.

If you use the default main core engine, all globals disappear as soon as the script completes. If you use the session engine, all global variables are retained while the host application continues to run. This means that if you run the script:

 #targetengine "session" var test = "test"; 

and then run the script:

 #targetengine "session" alert(test); 

you get a window with the message test instead of giving an error

In addition to the two standard "core" and "session" engines, you can create your own, with arbitrary names, so if you run the script

 #targetengine "mine" var test = "another test"; 

and then run

 #targetengine "mine" alert(test); 

you will get a window with another test message, but if you run it again

 #targetengine "session" alert(test); 

you get test anyway: there are two different β€œtest” global variables: one in the β€œsession” engine and one in the (recently created) β€œmine”.

+26
source

This discussion was raised on the Slack channel that I am watching. One long-time developer said the following (corrected a little for clarity):

As far as I know, //@targetengine only works on InDesign (possibly including InCopy) and Illustrator.

It works correctly in InDesign, but not in Illustrator. However, as far as I know, all other applications can use target machines with C ++, and this is what CEP does with each CEP [extension?], Which has its own isolated engine.

There are at least 3 types of engine.

  1. main engines, in InDesign it is a temporary engine that forgets everything after script execution.

  2. Public Private engines, such as session which is remembered and active after the script is executed and is suitable for event listeners. These and main can be defined using $.engineName and found in ESTK / vsCode

  3. Private Private $.engineName will show that "" can only be created with C ++ by using most applications and CEP, with the exception of InDesign, where CEP uses Public Private mechanisms that can be selected.

He thinks there is a fourth type that he forgot

0
source

All Articles