3

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.

ahle6481
  • 565
  • 2
  • 14

1 Answers1

3

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

kglr
  • 394,356
  • 18
  • 477
  • 896