I try to use NotebookOpen with the Wolfram Engine. As far as I know Wolfram Engine does not include the notebook interface, but it does include the FrontEnd functionality, so I tried

UsingFrontEnd[nb = NotebookOpen["path/to/notebook/code.nb", Visible->False]];

At first glance this seems to work, but using the NotebookObject with another function like NotebookImport fails:

    nb = NotebookOpen["path/to/notebook/code.nb", Visible->False];
    cellsExpressions = NotebookImport[nb, _->"Expression"];

NotebookImport::notanb: No notebook file found at NotebookObject[<< code.nb >>].

Using it with NotebookRead also fails:

    nb = NotebookOpen["path/to/notebook/code.nb", Visible->False];
    cells = Cells[nb];
{$Failed, $Failed, $Failed, $Failed}

To me it seems that the notebook is not kept open by NotebookOpen when being used in the Wolfram Engine. This leads to problems as documented for example in the NotebookRead documentation:

If an object is no longer valid, NotebookRead returns $Failed. If a list of objects is given, then $Failed will be returned for each of the invalid objects.

Interestingly Cells[nb] seems to yield the CellObjects associated with the notebook cells.

Is there a way to make NotebookOpen work with the Wolfram Engine?


Your Answer

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

Browse other questions tagged or ask your own question.