[vtkusers] [Python+vtk] Attaching user data to a vtkobject
David Gobbi
dgobbi at irus.rri.on.ca
Wed Jan 24 13:45:43 EST 2001
On Wed, 24 Jan 2001, Eric Boix wrote:
> Dear vtk+Python users,
>
> When using Python I try the following :
> QuadActor = vtkActor()
> QuadActor.myuserdata = "junk"
> I get the following message (on the last above line) :
> TypeError: object has read-only attributes
>
> This is probably due to the fact that the Python type of
> QuadActor is <type 'vtkobject'> (as opposed to <type 'instance'>)
> and hence has NO __dict__ attribute.
>
> What is then the natural way of attaching some user data to a 'vtkobject'
> at the Python level ?
> (I'm seeking a mecanism close to the Tcl/Tk bindtags and I naively thought
> that Python dynamic typing was a straightforward way of doing that...)
Hi Eric,
Right now the reason that you can't attach user data to a vtk-python
object is that there is no way to attach user data to the underlying
vtk-c++ object. Here is a not-so-straightforward explanation:
The way the python wrappers work, if all python references to a vtk-python
object are deleted, then the vtk-python object is deleted (and all
your attributes would be lost). If VTK still has references to the
vtk-c++ object, then the vtk-c++ object would still be around, and the
next time you access it through python (e.g. through a GetActors() call)
the attributes would not show up.
If you want to store user attributes for vtk-python objects, probably the
best way to do it for now is to have a global dictionary that uses the
python objects as keys.
Personally, I think it would be very nice if vtk-c++ objects could store
user attributes, but until that happens, I think that it is best if
vtk-python objects don't support user attributes either.
- David
--
David Gobbi, MSc dgobbi at irus.rri.on.ca
Advanced Imaging Research Group
Robarts Research Institute, University of Western Ontario
More information about the vtkusers
mailing list