1
$\begingroup$

I can select the first cell like this:

nb = CreateDocument[{a, b, c}, WindowTitle -> "Other"];
SelectionMove[nb, Next, Cell]

But how to select the first and the second cell?

$\endgroup$
  • 5
    $\begingroup$ closely related: Programmatically selecting non adjacent Cells $\endgroup$ – Kuba Sep 21 '16 at 18:42
  • $\begingroup$ @Kuba Little complex.Thanks :) $\endgroup$ – yode Sep 21 '16 at 18:49
  • $\begingroup$ @Kuba Maybe we can simulate lick Ctrl then move?? $\endgroup$ – yode Sep 22 '16 at 6:51
  • $\begingroup$ We can (30695) but you'd have to know where :) And as far as I'm concerned there is no way to do this withing MMA only, based on CellObject. $\endgroup$ – Kuba Sep 22 '16 at 7:04
1
$\begingroup$

Ah, now I recall why I emphasized "non adjacent" in Programmatically selecting non adjacent Cells

It is because you can select adjacent cells by mimicking what FE does when you use keyboard shortcuts:

Item[KeyEvent["Down", Modifiers -> {Shift}], "SelectNextLine"], 

-KeyEventTranslations.tr

So in our case:

  • Select the first cell for a set you want to select

  • Repeat token execution

SelectionMove[First @ Cells[], All, Cell]
FrontEndExecute @ FrontEndToken["SelectNextLine"]
$\endgroup$
0
$\begingroup$

You could create the Notebook with tags and later evaluate those. Notebooklocate also works with stored notebooks. Consider that the Cells maybe only are evaluateable if the type is set to "Input".

nb1 = CreateDocument[{Cell["a=2", "Input", CellTags -> "myTag"], 
   Cell["b"], Cell["c=3d", "Input", CellTags -> "myTag"]}, 
  WindowTitle -> "myCreation"]    

SetSelectedNotebook[nb1]
NotebookLocate["myTag"]
SelectionEvaluate[nb1]
$\endgroup$
  • $\begingroup$ No one said anything about evaluation :) $\endgroup$ – Kuba Sep 22 '16 at 10:32
  • $\begingroup$ Well, if one drops the last Part (SelectionEvaluate) it will only select the cells. I didn't thougth someone would only want to select severel cells without processing them. $\endgroup$ – crx Sep 22 '16 at 11:03
  • $\begingroup$ I see, but one may want to delete them, or change a background. Maybe you are right but I'm afraid the question is more general, so e.g. OP may want to select cells 1,2, do something, and the select cells 1,3. $\endgroup$ – Kuba Sep 22 '16 at 11:06

Your Answer

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

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