Re: access canvas created

From: Benjamin Bannier <bbannier_at_gmail.com>
Date: Fri, 19 Aug 2011 11:29:18 -0400


Hi SI,

> Is there a way to access to the canvas just created using the first method?

If you want to access a canvas with a certain name, e.g. the first canvas created with default constructor arguments (`new TCanvas()`) which has a name "c1" you can use

    gROOT->FindObjectAny("c1")

Pointers to the canvases are also accessible with `gROOT->GetListOfCanvases()`, so to get the first canvas created (no matter how it was created)

    gROOT->GetListOfCanvases()->At(0)

> in a macro I am creating a new canvas just giving the command
> new TCanvas()
> instead of 
> TCanvas *canvas1 = new TCanvas()
> to avoid declaring every time the object.

This sounds like a design problem. You should be able to just declare a single TCanvas

    TCanvas* canvas1 = new TCanvas();

at global scope, e.g. at the beginning of you macro and reuse it.

Benjamin

-- 
"Good judgment comes from experience. Experience comes from bad judgement."

Received on Fri Aug 19 2011 - 17:29:31 CEST

This archive was generated by hypermail 2.2.0 : Fri Aug 19 2011 - 17:50:02 CEST