3
$\begingroup$

I would like to use "Evaluate Initialization Cells" to open a CellGroup in a notebook. However, the following code doesn't work if placed in an initialization cell:

SelectionMove[SelectedNotebook[], Previous, CellGroup];
FrontEndTokenExecute["SelectionOpenAllGroups"]

When I manually press shift-enter (on the closed CellGroup), then it works as expected by opening the CellGroup. Unfortunately, if I place this code in an initialization cell (in the appropriate location before or after the CellGroup I wish to have opened), the CellGroup doesn't open.

Alternatively, is there an option I can set for CellGroups as there is for a single cell such as using SetOptions with CellOpen -> True?

$\endgroup$

1 Answer 1

4
$\begingroup$

This works :

SelectionMove[SelectedNotebook[], All, EvaluationCell];
SelectionMove[SelectedNotebook[], Previous, CellGroup];
FrontEndTokenExecute["SelectionOpenAllGroups"]

The problem was that in SelectionMove[SelectedNotebook[], Previous, CellGroup], Previous refers to the current selection which is not well defined when you do the initialization.

I have added the line SelectionMove[SelectedNotebook[], All, EvaluationCell]at the beginning so that the selection is the present cell during initialization.

$\endgroup$
1
  • $\begingroup$ Thank you Andre; that works very nicely indeed. $\endgroup$ Commented May 15, 2013 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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