Limitations on the getData option to the Notebook command?

The getData option to Notebook has this caveat.

Causes Igor to return the contents of the notebook in the S_value variable. **The contents are binary data in a private Igor format encoded as text**. The only use for this keyword is to transfer data from one notebook to another by calling getData followed by setData.

I have however been able to use getData=2 to copy a plain text string into S_value and process that string in other ways. It saves me one step (setting the selection to the entire notebook). But my use seems to go against the "private Igor format" statement.

Am I doing something here that could break later? Should I instead do the proper two step process to select the entire notebook and then do a GetSelection into a string?

getData=2 stores plain text in S_value. I believe this is very unlikely to change, so I think what you are doing is OK.

The documentation would be more precise if it said:

When used to fetch formatted text, the contents are binary data in a private Igor format encoded as text. Then the only use for this keyword is to transfer data from one notebook to another by calling getData followed by setData.

Hmm... I wasn't aware of that notebook keyword... Howard originally wrote all the notebook code; I've seen him lurking here since his retirement, so if he thinks he has something to add, maybe he will see this and respond.

I think your concerns are well-founded. It looks to me like it's primarily intended for Howard to test notebook subwindows. It may also be useful for programmatically transferring the contents of a notebook to a notebook subwindow.

Reading the source code, and doing a couple of simple experiments tells me that the contents of S_value are simply a big blob of bytes, the bytes that define the content of the notebook. In the case of a plain-text notebook, that's just UTF-8 bytes, and if you restrict yourself to simple ASCII, you can read it easily. If it's a formatted notebook, it includes all the binary-coded markers that indicate the formatting information. It can even have embedded nulls, so it's hard to read, but the text itself is in UTF-8.

My feeling is that for extracting and processing text that's stored in a notebook, it would be safer to use GetSelection. That is guaranteed to give you plain text (UTF-8) without embedded formatting, so you can even extract text from a formatted notebook for processing. And the words "private format" make me wonder if it might change in unpredictable ways. Though since Howard is retired that's less likely!

I hear you on the cumbersome nature of manipulating notebook selections to process text. But it works well, and should be guaranteed to continue working the same way for years to come. I've written Igor procedure code working with notebooks to process C++ classes to write some of the more voluminous boilerplate code need to handle, for instance, box plot preferences.

Thanks both (especially Howard from retirement). I have since switched to selection={} followed by GetSelection ...

If it's a formatted notebook, it includes all the binary-coded markers that indicate the formatting information.

That's true if you use getData=1 or getData=3 on a formatted text notebook. If you use getData=2 or getData=4, it returns plain text regardless of the type of the notebook (formatted text or plain text).

Originally getData and setData were added to support recreation macros for control panels containing notebook subwindows. I added some other flavors of getData=x to make it more generally useful, like for what jjweimer is doing.

I don't remember why the documentation warns about binary data for getData=2 and getData=4 which return only plain text. It may be that I did not think of updating the documentation when I added those modes.

 

Thanks, Howard. Your comment got there first, while I was composing, but I didn't get to see it until after I posted.