DynamicModule[{pts},
pts = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
Column[{
Button["Assign points", Export["temp", Dynamic[pts], "List"]],
LocatorPane[Dynamic[pts],
Dynamic[
Plot[Interpolation[pts][x], {x, 0, 3}, Frame -> True,
Axes -> False, PlotRange -> {All, {-1, 1}}, ImageSize -> 7 72]]
]
}]
]
pp = Import["temp"]
To start with your last question, the solution would be to remove the
Dynamic from within the Export function.
As to your main question: I guess you don't want to use a global
variable? Indeed, that woud defeat the purpose of the module, i.e. to
hide the variable pts from the global scope. I don't have an elegant
solution. Perhaps copying pts to a global variable if it is your
intention to hide pts?
Cheers -- Sjoerd
> Axes -> False, PlotRange -> {All, {-1, 1}}, ImageSize -> 7 72=
]]
> ]
> }]
> ]
>
> pp = Import["temp"]
First, you shouldn't be calling Export[] on Dynamic[pts]. You should be calling
it on pts. What you're exporting isn't the actual list of points, but a
Mathematica expression contained in a Dynamic. Try doing FilePrint["temp"] to
see what I'm talking about.
I recommend reading a post of mine from last month on Dynamic which should help
you to understand why that happened and why using Dynamic there was predictably
a bad idea...
http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00424.html
Of course, as you suspected, exporting to a temporary file is certainly not the
most convenient way. There's no reason that the Button[] can't interact with
variables outside of the Dynamic interface. You could have simply done this...
DynamicModule[{pts}, pts = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
Column[{Button["Assign points", thePoints = pts],
LocatorPane[Dynamic[pts],
Dynamic[Plot[Interpolation[pts][x], {x, 0, 3}, Frame -> True,
Axes -> False, PlotRange -> {All, {-1, 1}},
ImageSize -> 7 72]]]}]]
and then you can see the output by simply evaluating 'thePoints'.
Sincerely,
John Fultz
jfu...@wolfram.com
User Interface Group
Wolfram Research, Inc.
perhaps something like:
DynamicModule[{pts}, pts = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
Column[{Button["Assign points",
CellPrint[ExpressionCell[pts, "Input"]]],
LocatorPane[Dynamic[pts],
Dynamic[Plot[Interpolation[pts][x], {x, 0, 3}, Frame -> True,
Axes -> False, PlotRange -> {All, {-1, 1}},
ImageSize -> 7 72]]]}]]
could help?
Regards,
Yves
Hugh Goyder schrieb:
SetAttributes[SaveThePoints, HoldAll]
SaveThePoints[pnts_] :=
DynamicModule[{pts}, pts = {{0, 0}, {1, 0}, {2, 0}, {3, 0}};
Column[{Button["Assign points", pnts = pts],
LocatorPane[Dynamic[pts],
Dynamic[Plot[Interpolation[pts][x], {x, 0, 3}, Frame -> True,
Axes -> False, PlotRange -> {All, {-1, 1}},
ImageSize -> 7 72]]]}]]
and
SaveThePoints[p]
will save it to th variable p.
Regards
Jens