How to delete all current opening canvas before running a macro

Dear Rooters,

I write a macro that draws a graph. I would like to close all existing canvas at the beginning of the macro.

Could you please show me the way to do it.

For example:

void main()
{
// Step 1: Check if there is any opening canvas, if yes then close them.
// Step 2: Create a new canvas.
// Step 3: Draw Graph.
}

Thank you very much,

Ngoc Anh,


ROOT Version: 5.34
Platform: Window 7
Compiler: Not Provided


This is a function from tmva/test/tmvaglob.C for exactly this purpose:

void DestroyCanvases()
{
   TList* loc = (TList*) gROOT->GetListOfCanvases();
   TListIter itc(loc);
   TObject* o = 0;
   while (o = itc()) 
      delete o;
}
1 Like

Thank you very much. It works like a charm.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.