Changing view of a pad

I’m trying to manipulate the view of a pad from the command line, but I’m having difficulties. I know this is very similar to a topic from yesterday by Pim, but as opposed to him, I’m not using the Open GL viewer. I’m simply using the default viewer.

When I try to do this:

TView *view = gPad->GetView(); view->SetView(0,0,0,1); gPad->SetView(view); gPad->Modified(); gPad->Update();

I get the following error:

Error: illegal pointer to class object view 0x0 134 display_markers.cpp:65:
*** Interpreter error recovered ***

Am I going at this correctly? What am I doing wrong?

Marc

GetView only returns the pointer to the TView stored in the pad. See:
root.cern.ch/root/html/TPad.html#TPad:GetView
it does not create the TView if it does not exist. TView is usually created when a 3D plot is produced (lego, surface etc …). In the few lines you sent you do not check if the TView returned by GetView is valid or not…
Do you have a small running example (more complete) reproducing the problem ?

Thank you for your reply. I don’t know how to check if the view returned by GetView is valid or not.

Here’s a complete example:

[code]{
gROOT->Reset();

// create and open the default canvas
TCanvas *c1 = new TCanvas( "c1" );

// create a PolyMarker3D
TPolyMarker3D *pm3d = new TPolyMarker3D [3];
pm3d[0]->SetPoint(0, 100.4, 11.2, -25.0);
pm3d[1]->SetPoint(0, 112.6, -18.0, -11.1);	
pm3d[2]->SetPoint(0, 104.6, -69.8, -14.5);

for (Int_t i = 0; i < 3; i++)
{
	pm3d[i]->SetMarkerSize( 3 );
	pm3d[i]->SetMarkerColor( 3 );
	pm3d[i]->SetMarkerStyle( 3 );
	pm3d[i]->Draw();
}

TView *view = c1->GetView();
view->SetView(0,0,0,1);
c1->SetView(view);
c1->Modified(); 
c1->Update(); 	

}[/code]

{
   TCanvas *c1 = new TCanvas( "c1" );

   TPolyMarker3D *pm3d = new TPolyMarker3D [3];
   pm3d[0]->SetPoint(0, 100.4, 11.2, -25.0);
   pm3d[1]->SetPoint(0, 112.6, -18.0, -11.1);
   pm3d[2]->SetPoint(0, 104.6, -69.8, -14.5);

   for (Int_t i = 0; i < 3; i++) {
      pm3d[i]->SetMarkerSize( 3 );
      pm3d[i]->SetMarkerColor( 3 );
      pm3d[i]->SetMarkerStyle( 3 );
      pm3d[i]->Draw();
   }
   c1->Update();

   TView *view = c1->GetView();
   if (view) {
      view->SetView(0,0,0,1);
      c1->SetView(view);
      c1->Modified();
      c1->Update();
   } else {
      printf("Invalid TView\n");
   }
}

Aaah! I forgot to Update the pad after drawing my markers.

Thank you very much for your help, it works now!