# TikZ. Access node's name within a .code handler.

I'd like to place variable number of additional nodes on the border of the rectangle. I suggest it to look in a somewhat following way:

\node[name=R, my rectangle=top:3 bottom:1 left:2 right:1] {Node R};


or even better:

\node[my rectangle=top:3 bottom:1 left:2 right:1] (R) {Node R};


As nodes are not parts of the path and are stored for execution at the end of path construction, both cases should be equivalent. Anyway, this node definition should result in implicit defining of nodes/coordinates named, respectively: R top 1, ..., R top 3, R bottom 1, R left 1, R left 2, R right 1.

Having looked into pgfmanual I found there a key /tikz/name, but failed in accessing it's value from my rectangle/.code.

-

As far as I can tell, the node name is only available after the node has been constructed. Then it is stored in \tikzlastnode. You need to construct your additional nodes after the main node. This is done with the append after command key:
\begin{tikzpicture}

Your code will probably be quite similar to the code for creating labels. So you should have a look at the code below % Label and pin options in tikz.code.tex (in texmf/tex/generic/pgf/frontendlayer/tikz/).
after node path seems to be deprecated nowadays (I use PGF v2.10). Anyway, you've pointed me to the right direction. For those, who are interested, there is an option append after command. –  Dmitry Volosnykh Apr 9 '11 at 17:35