Mathematica provides access to $ModuleNumber
which can be enormously useful.
Unfortunately I can't find the equivalent for DynamicModule
.
I know such a parameter must exist for two reasons:
First, consider evaluating DynamicModule[{A}, Dynamic[A]]
four times:
DynamicModule[{A}, Dynamic[A]]
=> FE`A$$4
DynamicModule[{A}, Dynamic[A]]
=> FE`A$$5
DynamicModule[{A}, Dynamic[A]]
=> FE`A$$6
DynamicModule[{A}, Dynamic[A]]
=> FE`A$$7
This incrementation suggests the existence of such a variable.
Secondly, looking at the internals of DynamicModule
one finds references to a parameter serialno_
, specifically in FE`ExecuteInDynamicModule
Using UpValues
and print statements on like Refresh[FE`ExecuteInDynamicModule[a___],___]:>Print[{a}]
one finds that the second argument to FE`ExecuteInDynamicModule
(serialno_)
increments each time, but pulling back one step further to FrontEnd`SynchronousDynamicEvaluate[___,Refresh[FE`ExecuteInDynamicModule[a___],___],___]
provides no information, as FrontEnd`SynchronousDynamicEvaluate
does not directly provide a serial number and its DownValues give no hints for how to proceed.
Now, I also know that this parameter, whatever it is, is fundamentally a front end parameter, due to both looking at the evaluation chain and code of DynamicModule
and because this function:
frontEndModule[varSpec_, body_]] :>
Block[{Manipulate`Dump`$eDynamicModule = True},
DynamicModule[varSpec, body]
Behaves identically to the DynamicModule
behavior seen above, except in both following the code and in watching the evaluation chain, none of the heavy module-machinery of DynamicModule
is invoked.
Unfortunately after many hours of searching and testing I still do not know where to find this parameter, although I feel like I must be close with the serialno_
argument to FE'ExecuteInDynamicModule
.
I'm assuming the symbol will be in some front end context, because I've searched nearly exhaustively through the symbols of the various Manipulate
and Dynamic
contexts via a symbol-browser and an OwnValues
based test to see which symbols (using string pattern "*"
) are numeric did not reveal the answer, although I can confirm that it produced $ModuleNumber
, as a sanity check.
Does anyone know where to find this?
$xx
part will change anyway when you save/open the notebook with created DM. $\endgroup$$ModuleNumber
,FE`*
orFrontEnd`*
symbols. If it were, there should be some evidence in LinkSnooper while watching dynamic module instantiation, but I don't see any. Maybe you can query the FE to tell you the current number. $\endgroup$DynamicModule
will call a variable, which can be used in all the same ways as forModule
@ Michel E2 how would you suggest going about that? I've looked through pretty much every symbol inFE`
at this point. $\endgroup$Internal`GetTrackedSymbols[]
and finds the ID numbers that some functions clearly use to get the actual dynamic ID (i.e., the 44 inFE`A$44
). Unfortunately I can't figure out how to go from those numbers to that serial number, still. $\endgroup$