I've defined
\usepackage{zref-savepos}
\newcommand*{\curypos}[1]{%
\zsaveposy{#1}%
\zposy{#1}sp = %
\the\dimexpr\zposy{#1}sp\relax%
}
and that seems to work fine. Saying \curypos{some_label} reports the y position on the page, just as expected.
Now do
\newenvironment{mytest}[2]
{\write\myfile{\curypos{#1} #2}%
}
{% Do nothing to close out the environment.
}
\begin{mytest}{first}{second}
pointless blather
\end{mytest}
The contents of \myfile do not show the y-position on the page. Instead they show
\zsaveposy {first}0sp = 0.0pt second
For some reason, first is not passing through as an argument to \curypos.
I'm guessing that this is some form of fragility, so I tried using \protect in various places and declaring \curypos with \DeclareRobustCommand, but none of them work.