5
$\begingroup$

I have found that when GenerateDocument is called from a button within a complex interface that the function does not work, i.e. nothing happens, and the front end "stalls".

GenerateDocument["ExampleData/BasicTemplate.nb", <|"author" -> "Henry Jones"|>

I use the term "stall"s because the symptoms are different from a front end freeze where you typically, on OS X, see the spinning rainbow wheel. The front end is inactive for a period of time but no rainbow wheel.

GenerateDocument typically wants to create a temporary cell with a progress bar, so if that is not possible within the interface could this be the cause of the problem? If so how do I fix it?

$\endgroup$
  • $\begingroup$ It involves FE to finish so my guess is Method -> "Queued" should help. And it makes a difference on Windows. Does it work for you? $\endgroup$ – Kuba Oct 23 '18 at 6:40
  • $\begingroup$ @Kuba It makes no difference. No "obvious" things worked until I spelunked the function. $\endgroup$ – Mike Honeychurch Oct 23 '18 at 8:40
  • $\begingroup$ I see, anyway for completeness, the example from the question in Windows gives 'packet error' for regular button but works well with Queued Method. $\endgroup$ – Kuba Oct 23 '18 at 8:44
  • $\begingroup$ The entire button operation in this interface, of which GenerateDocument is just a part would never work without Method->"Queued" due to the length of time taken. Additionally the answer described here does not take any longer than the docs example without these options. The only difference is bypassing UsingFrontEnd $\endgroup$ – Mike Honeychurch Oct 23 '18 at 10:57
4
$\begingroup$

The internal functions being used by GenerateDocument is GenerateDocumentDriver, which has 4 options, "PostProcess" -> True,"HeadlessMode" -> False,"ProgressIndicator" -> True,"RetainAsTemplate" -> False.

"HeadlessMode" is used by another internal function postProcessReplacedNotebook. The "HeadlessMode" option controls whether UsingFrontEnd is being used. It appears that when this function is used it can "inhibit" other front end behaviour at times.

This code allows everything to work but doesn't quite get us the desired result:

GenerateDocument["ExampleData/BasicTemplate.nb", <|"author" -> "Henry Jones"|>,
"ProgressIndicator" -> False,"HeadlessMode" -> True]

enter image description here

Wrapping with CreateDocument fixes everything and produces the desired output without any front end issues:

CreateDocument@GenerateDocument["ExampleData/BasicTemplate.nb", <|"author" -> "Henry Jones"|>,
"ProgressIndicator" -> False, "HeadlessMode" -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.