3

The function Context[] returns the context of the Notebook the function is called in.

Is there a function where we can specify e.g a Notebook object and retrieve the context from that file?

I'm creating a palette where I want to change a variable located in a Notebook that has the context local to that notebook. From the palette I would like to use SelectedNotebook[] and retrieve the context.

Thx for advise!

rhermans
  • 36,518
  • 4
  • 57
  • 149
Lou
  • 3,822
  • 23
  • 26
  • 1
    Can you give a tiny example of such a palette, to get a better idea of what you need? What if the context is unique to cell groups instead of notebooks? How does the palette obtain the variable name? – Szabolcs Sep 08 '17 at 09:55
  • 1
    Also, Context[] does not need to be notebook's CellContext, e.g. if Begin/BeginPackage was used. – Kuba Sep 08 '17 at 10:00
  • 1
  • 1
    I guess a more concrete question would be: How do we evaluate code as if it were entered at the current cursor position in the notebook? – Szabolcs Sep 08 '17 at 10:36
  • I would like to have multiple notebooks with private context. All these notebook wil have a variable "data". with the Palette I would like to modify the values (email, phone, names etc) contained in data with a PaletteNotebook combined with inputfields etc. Using Dynamic[data] will show the change and the Palette will also write the results to a file – Lou Sep 08 '17 at 14:09
  • @Szabolcs it is possible to do that when I "know" the context (eg I give it the name of the notebookfile) but perhaps more error prone. – Lou Sep 08 '17 at 14:34
  • 1
    Do you really need a palette? Would a function (loaded from a package) work instead? How about a palette that writes myFunction[data] into the notebook (perhaps along with a Needs)? Maybe automatically insert that as an input cell, then evaluate it. Maybe even delete it after evaluation, if that's what you prefer. – Szabolcs Sep 08 '17 at 14:48
  • @Szabolcs That is a valid alternative and easier to implement. So basically the Notebooks have standard a Needs (to package with function) in the evaluation Cell and then just shoot in a cell and evaluate it there and remove the original input cell (so the output cell has the formatted Grid etc). It also might be a safer alternative with multiple NB's open. – Lou Sep 08 '17 at 15:18

0 Answers0