Skip to main content
11 events
when toggle format what by license comment
Aug 12, 2015 at 10:39 vote accept ibeatty
Aug 12, 2015 at 6:00 comment added MarcoB @ibeatty I took the liberty of turning Szabolcs' comments into an answer. You might consider accepting it, so the question might be more interesting to future readers with similar problems.
Aug 12, 2015 at 5:59 comment added MarcoB @Szabolcs I took the liberty of turning your extended comments into an answer, since the OP confirmed that it solved his problem. Please feel free to edit it at will, or let me know if you'd rather remove it instead.
Aug 12, 2015 at 5:58 answer added MarcoB timeline score: 3
Aug 8, 2015 at 15:54 comment added ibeatty @Szabolcs, if you turn your comment into an answer, I'll accept it. It's solved my problem, even though I don't fully understand the details.
Jul 10, 2015 at 19:45 comment added ibeatty I tried NotebookRead and ToExpression, and ran into a problem with the fact that the chunk of notebook content was "not a string or box". I suspect that's what your Cases bit is for. I'll mess around with your latest suggestion, while hoping a notebook-programming wizard happens by. Thanks!
Jul 10, 2015 at 19:30 comment added Szabolcs You could replace the SelectionEvaluate with this function: ev[nb_] := Module[{r}, r = NotebookRead[nb]; ToExpression /@ Cases[r, Cell[boxes_, "Input", ___] :> boxes, {0, Infinity}] ]. It will evaluate the contents of those cells. But: 1. This is very likely not the right way, and might break in some cases. I'm not experienced with notebook programming. 2. While it evaluates the contents of those cells, it does not link that content to the cells themselves. You won't get new In/Out labels and you won't get associated output cells.
Jul 10, 2015 at 19:24 comment added Szabolcs Instead of asking the front end to send those cells to the evaluation queue, you can just read the cell expression directly and let it evaluate. I'm not experiences enough with notebook programming to know how to do that off-hand. Something with NotebookRead and ToExpression, probably.
Jul 10, 2015 at 19:19 comment added ibeatty @Szabolcs, that makes perfect senses. So now I'm wondering whether Mathematica has any other infrastructure that would let me get the effect I want. I can't seem to find much documentation on working with the evaluation queue. I suppose I might be able to use SelectionEvaluate twice, once for the Section 1 bit and again for everything else I'll need to execute after it, but I'm hoping to eventually move most of the Section 2 code off into a package, and have a very minimal "Test it!" button that invokes it. I don't think I could use the same named-cell trick very easily for that.
Jul 10, 2015 at 19:10 comment added Szabolcs I think this is what happens: When you are "evaluating" a cell in the front end it really just queues that cell for evaluation. When you evaluate section 2, you first queue all cells there for evaluation. The SelectionEvaluate queues some more cells, from section 1. But at this point the queue is not empty yet, it still contains cells from section 2, to be evaluated later. The SelectionEvaluate function inserts section 1 cells only at the end of the queue, after the section 2 cells.
Jul 10, 2015 at 18:34 history asked ibeatty CC BY-SA 3.0