Hi all,
This is one of those "please read it carefully and don't confuse the issue by uninformed guesswork" kind of posts. Please read it carefully and don't confuse the issue by uninformed guesswork.
When you create a document template and a template fragment, and the fragment is of the Custom Script variety, it only works once per session when you use the DocumentGenerator API (meaning you have to restart EA after each generation).
Subsequent attempts to generate the same document fail with the parent template working correctly, but the fragment producing no content at all. If you run the same document generation from the dialog, it works every time.
Some details.
A Custom Script fragment calls a function in a JScript script, which returns XML data. Has to be JScript for EA to accept it.
My generation script which uses DocumentGenerator is written in VBScript. If that script is in JScript, the generation always fails. Presumably this is due to the same bug, but that just affects me the toolmaker, not the end users.
When I say the fragment produces no content, this includes constant stuff (table header) outside the
custom> content tag. Nothing is produced.
Content in the parent template which appears after the fragment does produce output, so the whole generation process doesn't break, just the fragment sub-process.
I've tried to trace how EA executes the document generation in the two cases.
When run through the GUI, the main document generation thread appears to reside in the EA process. Each Custom Script fragment gives rise to one SScripter/conhost process pair. (SScripter is EA's script runner executable, conhost is Windows' Console Host.)
In a template with multiple fragments, it looks like the SScripter process for one fragment remains for about half a second after the process for the next fragment has started up, but that might just be delays in the reporting. (I'm using the Windows Task Manager.)
Anyway, it works as expected and a trace printout in the fragment script comes out in EA's system output window.
When run through the API, there's one SScripter/conhost process pair for the main script, so far so good.
Then, the first run through the generation script, each fragment's SScripter/conhost start up, run and finish, one at a time as above.
In subsequent runs, however, the fragment processes never start. No content is generated for the fragment, and no trace printouts appear. DocumentGenerator.GetLastError() immediately after DocumentGenerator.DocumentPackage() reports nothing.
The generation script takes far less time to run, so it doesn't appear to hang-wait-timeout but rather to encounter an error and give up straightaway. I can find no zombie processes hanging around after the generation is completed, either when it works or when it fails.
I've monitored the various temp directories, and the only one where I find activity is AppData\Local\Temp, where EA creates three temp files on startup. The VBScript generation script gets "compiled" into a file here as well, which is then passed to SScripter (and deleted upon conclusion), but the JScript fragment scripts are handled differently and are not written to any files here.
I've had a look at the SScripter command line. It looks like this
SScripter.exe arg1 arg2 "arg3" "arg4" "arg5"From what I can ascertain, the arguments contain the following:
- arg1: A number, unknown content; probably a reference to the package being documented but doesn't match anything in t_package or t_object.
- arg2: A number; the PID of the EA session which launched the script runner.
- arg3: A string; the GUID of the script in t_script.
- arg4: A string containing a decimal number; probably a magic number telling SScripter what type of script is to be executed (suspiciously even in hex).
- arg5: A string; either "Console" (for fragment scripts) or the file name of the "compiled" VBScript script in AppData\Local\Temp.
Now all this is mainly in order to show what a brilliant person I am, but also serves a background to the real question:
Is there a way to force a cleanup or reset so that the JScript fragments can be run multiple times through the API?I can see nothing in the API itself, and I've found nothing in the temp directories (and EA's three temp files do not get modified during a generation run), but there's got to be something somewhere that's left over from the first run and then not reset until a new session is established.
"New session" means restarting EA. Reloading the project doesn't resolve the issue, neither does closing and re-opening it.
It would also appear that the behavior when using a Document Script fragment (where the script returns RTF) is similar, but worse: there running the generation through the API fails every time, but it does work when running it through the GUI.
However, I haven't analyzed this in any detail.
And finally, this is all in 13.5. We will upgrade in the next few weeks, but I need to have this document generation done before that.
/Uffe