Python Tips and Notes

From KitwarePublic
Revision as of 21:22, 2 September 2009 by Tmjung (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Introduction

In this section I'll detail some of the tools and methods that can be useful when you are unable to implement something.

The first things you should know are the things that are not currently possible (as of 3.6.0). -Plotting through python is not currently implemented. -Using the axes widgets in python is not possible yet.

If you know what you are looking for but can't seem to find it try looking at the VTK documentation VTK documentation. It can help you see the structure of some of the objects you may be manipulating.

If you are having trouble with something very often the culprit is some uninitialized variable. Some things are left empty where they would be filled in when using the GUI. One way to figure out what the problem is to replicate what you are trying to do in the GUI and then systematically go through the objects in the python shell (in the GUI) and find differences in values.

The above technique can also be useful for camera positions that are difficult to get to. Move the camera using the mouse and then go into the python shell and get the coordinates for the camera using <source lang="python">camera.GetPosition()</source>. Note that the orientation will likely be different so those values will have to be noted as well.

A useful way to inspect an object on the fly is to simply use <source lang="python">dir(object)</source> to look for useful properties. Always keep in mind that just because something has a value represented in python by an integer or string, doesn't mean that it doesn't also have internal properties which can be adjusted.


Acknowledgements

Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear Security Administration under contract DE-AC04-94AL85000.