The \pgfkeysvalueof macro only works with actual value-keys.
Due to, I guess, legacy reasons, the keys xstep and ystep just define another macro (here \tikz@grid@x and \tikz@grid@y) even though they could as well have been value-keys.
And step just sets these two macros to the same value? No, because it also allows a value in the form of a coordinate (starting with () and sets the xstep to that coordinate's x value and the ystep to that coordinate's y value.
Even if we find a way to retrieve the value that has been given to one of these keys, one needs to think about how to deal with step = (15:1cm).
Well, you can always add more stuff to an already existing key, say,
@step/.initial=1cm,
step/.append style={/tikz/@step={#1}}
and then \pgfkeysvalueof{/tikz/@step} returns the value that was given to step last (which might as well have been (15:1cm)!).
We could re-write how xstep, ystep and step work:
\tikzset{
xstep/.initial=1cm,
ystep/.initial=1cm,
}
\makeatletter
\def\tikz@step@single#1{%
\pgfkeyssetvalue{/tikz/xstep}{#1}%
\pgfkeyssetvalue{/tikz/ystep}{#1}}
\def\tikz@step@point#1{%
\pgf@process{#1}%
\pgfkeyssetevalue{/tikz/xstep}{\the\pgf@x}%
\pgfkeyssetevalue{/tikz/ystep}{\the\pgf@y}}
\def\tikz@grid@x{\pgfkeysvalueof{/tikz/xstep}}
\def\tikz@grid@y{\pgfkeysvalueof{/tikz/ystep}}
\makeatother
and now you can use \pgfkeysvalueof{/tikz/xstep}/\pgfkeysvalueof{/tikz/ystep} …
but then you still have the case of step = 1 since TikZ allows dimension-less units to be used with the xy coordinate system. (Dimension-less units in minimum size will be interpreted as pt.)
In your case, you are explicitly using step=5mm and putting grid lines inside pixel so you're side-stepping all these problems but I want to highlight how complex this can get when you factor in all general possibilities and use cases.
All that to say that Andrew Stacey's solution is a much cleaner way to this and give you (or your users) much better control over what gets drawn. Just don't forget to use only dimensions with units for pixel/size.
line widthproperty fromgrid lines. However, how can I assign thegrid lines/stepproperty topixel/minimum size? I've now simplified the question. – lemzwerg Oct 08 '22 at 06:59pixel/line widthandpixel/sizewhich then thegrid linesandpixelstyles use. So rather than try to read from a separate style, you effectively have a "parent" style that sets both. – Andrew Stacey Oct 08 '22 at 07:11\def\gridStep{5mm}and use this value in both styles. Still, this is far from elegant IMHO. The right way would really be assign one key value to another key, and I wonder how this can be done – actually, I can't believe that I'm the first person who wants to do something along this way... – lemzwerg Oct 08 '22 at 07:17