I have a large number of functions which I am combining into packages and will call those functions via a palette. I then use those functions in a notebook and may need to call them several times. The data entry for many of those functions is via a dynamic interface, which gives a nice check on the data as it is entered. My problem is that, if I call the same function twice in a Notebook then entering the data each time the function is called changes the data for the previous function already in my notebook. Is there a way around this?
Here is my code. It calls other functions which can be ignored. If you evaluate it and then type Example twice and change the pile dia in the pop up menu you will see it changes it in the first call to the function as well.
example =
Module[{h, c, ϕv, ϕ, nbar, fcu, fy, fyv, Nd, Md, Vd},
fy = 500; fyv = 500;
Dynamic[
Deploy[Style[
Panel[Grid[{{"Pile Dia mm",
PopupMenu[
Dynamic[h], {600, 225, 250, 300, 350, 400, 450, 560, 570,
600, 760, 900, 1050, 1200, 1350, 1500}],
"Cover to links mm",
PopupMenu[
Dynamic[c], {75, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
100}], "\!\(\*SubscriptBox[\(f\), \(cu\)]\) MPa",
PopupMenu[
Dynamic[fcu], {30, 25, 30, 32, 35, 40, 45,
50}]}, {"Dia of links mm",
PopupMenu[Dynamic[ϕv], {10, 6, 8, 10, 12, 16}],
"Main bar dia mm",
PopupMenu[Dynamic[ϕ], {25, 10, 12, 16, 20, 25, 32, 40}],
"No. of main bars",
PopupMenu[
Dynamic[nbar], {6, 4, 6, 8, 10, 12, 14, 16, 18,
20}]}, {"\!\(\*SubscriptBox[\(f\), \(yv\)]\) MPa",
InputField[Dynamic[fyv], Number, FieldSize -> Small],
"\!\(\*SubscriptBox[\(f\), \(y\)]\) MPa",
InputField[Dynamic[fy], Number,
FieldSize ->
Small]}, {"\!\(\*SubscriptBox[\(N\), \(d\)]\) kN",
InputField[Dynamic[Nd], Number, FieldSize -> Small],
"Md kNm",
InputField[Dynamic[Md], Number, FieldSize -> Small],
"\!\(\*SubscriptBox[\(V\), \(d\)]\) kN",
InputField[Dynamic[Vd], Number,
FieldSize -> Small]}, {Dynamic[
Last[PlotPile[h, c, ϕv, nbar, ϕ]]],
Button["Calculate", {Print["Interaction Diagram - Pile dia=",
h, "mm with ", nbar, " bars ", ϕ, "mm dia."],
Print[Last[
Interaction[h, c, ϕv, nbar, ϕ, Nd, Md, fcu,
fy]]], pilelinks[Vd, h, c, fcu, fy, fyv,
nbar, ϕ, ϕv, fcu, fy]}]}}]]]]]]
Module
withDynamic
; don't do that. Replace it withDynamicModule
and try your code again. Does it work? $\endgroup$ – Mr.Wizard Mar 29 '15 at 16:06