# How to find out if a cell is member of a closed group

I have a While-Loop lurking through a notebook. I want to find out - among other things - if a cell is not visible because it is a member of a closed group. I tried various things, see xxx below. But maybe the CurrentValue-Aproach is not the right thing at all, maybe some FrontEndToken-thing would work.

Can someone help or point to the right thing.

Here is an example. The fist cell is a "Chapter"-Cell, the second is a "Text"-Cell which is the "head" of a group which is closed via cell brackets double-click.

My favorite was CellOpen but it gives True in both cases.

xxx="ShowSelection"; (* Both True *)

xxx="Background"; (* Works well *)

xxx="CellOpen"; (* Both True *)

xxx="Visible";  (* Both True *)

xxx="CellGroupData";  (* Both $Failed *) xxx="ShowClosedCellArea"; (* Both False *) xxx="CellGroup"; (* Both$Failed *)

Row[{"Test is: ",xxx }]

SelectionMove[book,Before,Notebook];

SelectionMove[book,Next,Cell]; Last@SelectedCells[]

SelectionMove[book,Next,Cell]; Last@SelectedCells[]

CurrentValue[Last@SelectedCells[],xxx]

SelectionMove[book,Next,Cell]; Last@SelectedCells[]

CurrentValue[Last@SelectedCells[],xxx]

• Although I would still be interested in a possible solution I figured out to use SelectionMove[..., CellGroup] and then pick the first cell from the selection. That's what I wanted, to avoid closed cells May 11 '17 at 22:18

My favorite was CellOpen but it gives True in both cases.

You misinterpret the meaning of the option CellOpen. This option is NOT related to cell grouping at all, it just hides the contents of a Cell when is set to False for that Cell.

One way to find out whether the cell is a member of a cell group is to attempt to select the cell group and then check whether the attempt is failed. Using the method from this answer,

nb = CreateDocument[CellGroup[{a, b}], CellGrouping -> Manual]

cellObj = First@Cells[nb]
SelectionMove[cellObj, All, CellGroup]
If[Length@SelectedCells[nb] == 0,
Print["The cell is not a member of a cell group!"],

"FirstCellInGroup" /. DeveloperCellInformation@cellObj

• Note that the second argument to CellGroupData can be a Dynamic expression, so that would have to be checked, too. Oct 7 '17 at 16:07
• @b3m2a1 Do you have an idea how it could be done (I mean, obtaining the value of Dynamic expression)? Oct 7 '17 at 16:09
• That's a hard question. The simplest option is Setting but in general dynamic evaluation obviously can depend on the cell evaluating it and all sorts of other factors. I've seen InternalDynamicEvaluate before but don't know how to make it work. Oct 7 '17 at 16:14
• @b3m2a1 Simple application of Setting to the output of NotebookRead fails, tried with nb = CreateDocument[CellGroup[{Dynamic[a], b}, Dynamic[a]], CellGrouping -> Manual]. The problem seems to be hard indeed. Oct 7 '17 at 16:51