# Export in Manipulate, infinite loop

I want to make export of a plot inside Manipulate, but only once. However, this code runs infinitely and does export infinitely:

Manipulate[Module[{pl},
pl = Plot[Sin[a x + b], {x, 0, 6}];
Export["pl.pdf", pl];
pl]
, {a, 1, 4}, {b, 0, 10}]


If I remove Export[] from Manipulate, problem disappears, but I need it inside Manipulate for other reason;)

Can we control number of evaluations of certain code inside Manipulate?

-
Can you please add version information? Which OS and which Mathematica version you are using? –  Nasser Aug 14 '13 at 17:23

What about this (sans Module):

Manipulate[pl = Plot[Sin[a x + b], {x, 0, 6}], {a, 1, 4}, {b, 0, 10},
Button["Export", Export["pl.pdf", pl]]]


-
"Clean clean" ♪ ♫ +1 –  Mr.Wizard Aug 14 '13 at 16:04
@Mr.Wizard whuzzat (non sequitur)? –  Yves Klett Aug 14 '13 at 16:07
Well, I looked at your answer and thought "that's clean." Then I thought of this. Yes, I know I'm weird. :o) –  Mr.Wizard Aug 14 '13 at 16:09
LOL! Now I have to get that out of my head, thank you :-) –  Yves Klett Aug 14 '13 at 16:14
But really the question was on why using Export was causing a Continuous updating since it should not be the case. I say this is bug or bad design somewhere in export. The 2 solutions given are simply work around. The problem itself has not gone away, because again, calling export[] should not have caused this. Even when adding SynchronousUpdating -> False which means do not time out, the Continuous updating is still there. –  Nasser Aug 14 '13 at 16:58

It is a Dynamic problem. Export seems to be tagged dynamic somewhere. This is workaround. When I saw this, I remembered similar problem few days ago, and I used the same trick given there and it worked.

I set SynchronousUpdating -> False and ContinuousAction -> False else it will be very slow since you'll be trying to make a pdf file for each small tick change. Now a PDF file will be created when you release the mouse only from the slider.

SetDirectory[NotebookDirectory[]]; (*so we know where the PDF file is *)

Manipulate[

Module[{x},
pl = Plot[Sin[a x + b], {x, 0, 6}];
myExport["myPlot.pdf", pl];
pl
],

{a, 1, 4},
{b, 0, 10},

SynchronousUpdating -> False,
ContinuousAction -> False,

Initialization :>
(
myExport[type_String, p_] := myExport[type, p] = Export[type, p]
)
]


Update

The problem as I saw it, is why Manipulate continue to update when using an Export when though Export is clearly not updating any of the control variables. On V 9.01, these are animations showing the problem. First animation is the original code posted above, and the second one, after adding SynchronousUpdating -> False.

The real question I assumed why: Why does this happen.

and

-