Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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.

share|improve this answer
    
Thank you Andre; that works very nicely indeed. –  zentient May 15 '13 at 19:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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