2
$\begingroup$

There must be a possibility to convert a CounterBox into a number. For example

CounterBox["Page", {FileNameTake[bookUrl], "someTag"}] 

The suggestion

book = NotebookOpen[bookUrl]; CurrentValue[NotebookSelection[book], {"CounterValue", "Chapter"}] 

does not work (if the cell is selected programmatically).

I don't know how to referene a cell with a special tag with CurrentValue, but I presume that wouldn't work either.

I don't know why I have the hint here that this question is "subjective"??

I would appreciate any help.

$\endgroup$
4
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$ Commented Mar 8, 2016 at 12:39
  • $\begingroup$ "... the hint here ..." -- where is "here"? $\endgroup$ Commented Mar 8, 2016 at 12:47
  • 1
    $\begingroup$ CurrentValue[SelectedCells[], {"CounterValue", "Section"}] works fine, yet I don't know if that's the answer. The question is a little bit chaotic. $\endgroup$ Commented Mar 8, 2016 at 12:49
  • $\begingroup$ Thank you for the comments, I will follow the instruction in future posts. The "hint" came up in a yellow window shortly after I typed the title of my question. Sorry, I am rather new in this forum. $\endgroup$ Commented Mar 8, 2016 at 22:40

1 Answer 1

6
$\begingroup$

Your basic idea seems to work for me. I used Cells instead of NotebookSelection. I tagged a cell with the tag "C2", so that the cell looked like this:

Cell["Stuff", "Text", CellChangeTimes->{{3.666429490958235*^9, 3.666429492522786*^9}}, CellTags->"C2"] 

Then CurrentValue returns a number:

enter image description here

It even works in another notebook. Let nb be the other notebook object.

foo = CurrentValue[ First@Cells[nb, CellTags -> "C2"], {"CounterValue", "Chapter"}] (* 2 *) 

Note book selection works, too. Below I had selected the "Hi there!" cell.

foo = CurrentValue[ NotebookSelection[nb], {"CounterValue", "Chapter"}] (* 1 *) 
$\endgroup$
3
  • $\begingroup$ Thank you Michael for your very well documented answer. Finally i tried this on my raspberry pi with version 10. And it works! But not on my version 9!! with Windows. What can be the reason? A lot of things with CurrentValue do work, but nothing with counters like Section, Page, etc. What might be the reason? Is there a bug? Or might it be some fancy Option somewhere? Or the fact that I have also an older version of mathematica installed on my system? I read somewhere that this might cause some trouble (but I never encountered any). $\endgroup$ Commented Mar 8, 2016 at 23:18
  • $\begingroup$ Hallo, maybe I shouldn't have marked this as answered. I still need a workaround because CurrentValue[] command doesn't work in version 9. And also i wonder if there is a possibility to get this NUMBER, which is generete by the CounterBox[] command and which is to be seeeen in the output. I tried a lot of things, even CopyToClipboard[%] an similar things. When I try to copy the selected number I always get the underlying CounterBox[] command. Has someone an idea? Don't want to post a question again. $\endgroup$ Commented Mar 10, 2016 at 17:32
  • $\begingroup$ @Darwin1871 Thanks for letting me know. Feel free to unaccept, if it doesn't solve your problem. I can't explore V9 as I have V10. You may edit the question to clarify your needs. Maybe someone with V9 will be able to help. My docs say that CurrentValue hasn't been updated since V9, so I'm surprised it doesn't work. Or maybe the docs are wrong. Who knows. $\endgroup$ Commented Mar 10, 2016 at 17:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.