2
$\begingroup$

I want to print a dynamic output while some code is running and then automatically delete it when when the output is done. PrintTemporary is not quite what I am looking for -- I want the output to be deleted from inside the module rather than when the cell is done evaluating because I want to evaluate several modules in the same cell. Here is an example of what I am looking for:

test[steps_]:=Module[{},
    n=0;
    Print["% Complete: ",Dynamic[n*100/steps]];
    For[n=0,n<steps,n++,
        (*CODE RUNS*)
    ];
    (*Delete Output Cell*)
]

I want to explicitly delete the output cell created when running test, but cannot find the commands to do so. All I have seen on stackexchange is how to delete ALL output cells or how to print temporarily, which I do not want.

$\endgroup$
2
$\begingroup$

Perhaps something like:

test[steps_] := Module[{}, n = 0;
  Print["% Complete: ", Dynamic[n*100/steps]];
  For[n = 0, n < steps, n++, Pause[1]];
  NotebookFind[SelectedNotebook[], "Print", All, CellStyle]; 
  NotebookDelete[]]

enter image description here

See also: A self-deleting button to delete Print cells

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.